-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathQuestions.java
72 lines (52 loc) · 1.39 KB
/
Questions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package recursion;
import java.util.Scanner;
public class Questions {
public static void main(String[] args) {
String a = "abcba" ;
System.out.println(palindrome(a, 0, a.length()-1));
reverseString(a);
}
static boolean palindrome(String s , int l , int r) {
if(l == r ) {
return true ;
}
if(s.charAt(l) != s.charAt(r)) {
return false ;
}
if(l < r+1 ) {
return palindrome(s, l+1, r-1);
}
return true ;
}
static void reverseString(String s) {
if(s.length() == 1) {
System.out.println(s);
} else {
System.out.print(s.charAt(s.length()-1));
reverseString(s.substring(0,s.length()-1));
}
}
static void subsequenceString(String s) {
// A String is a subsequence of a given String, that is generated by deleting some character of a
// given string without changing its order.
subsequenceString("abc", "");
}
static void subsequenceString(String ques, String ans) {
if(ques.length() == 0) {
System.out.print(ans + ", ");
return;
}
subsequenceString(ques.substring(1), ans+ques.charAt(0));
subsequenceString(ques.substring(1), ans);
}
public static void main (String[] args) {
int a[] = {1, 2, 3, 5} ;
shuffle(a , 3 , 3);
}
static void shuffle(int arr [] , int n , int a ) {
if(a-n >= 0 ) {
System.out.print(arr[a - n] + " " + arr[n/2 + 1] + " ");
shuffle(arr , n-1 , n);
}
}
}