Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b5c2a0f

Browse files
committedJan 24, 2022
added problem with solution
1 parent 765ec7f commit b5c2a0f

File tree

7 files changed

+117
-0
lines changed

7 files changed

+117
-0
lines changed
 

‎.idea/runConfigurations.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/StringFormation.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.Arrays;
2+
3+
public class StringFormation {
4+
public static void main(String[] args) {
5+
StringFormation obj = new StringFormation();
6+
System.out.println(Arrays.toString(obj.divideString("abcdefghij", 3, 'x')));
7+
}
8+
public String[] divideString(String s, int k, char fill) {
9+
10+
int length = s.length();
11+
12+
int arraySize =(int) Math.ceil((length*1.0)/k);
13+
String[] str = new String[arraySize];
14+
15+
for(int i=0;i<s.length();i++){
16+
int val = (int)Math.ceil(i/k);
17+
if(str[val] == null){
18+
str[val] = "";
19+
}
20+
str[val] += s.charAt(i);
21+
}
22+
for(int i=str[arraySize-1].length();i<k;i++){
23+
str[arraySize-1] += fill;
24+
}
25+
26+
return str;
27+
28+
29+
}
30+
}

‎src/number_problem/EvenOrOdd.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package number_problem;
2+
//using bitwise
3+
public class EvenOrOdd {
4+
public static void main(String[] args) {
5+
int a= 17;
6+
if((a &1)==1){//first a will be converted into binary and then and operation will happen
7+
System.out.println("odd");
8+
}else{
9+
System.out.println("even");
10+
}
11+
}
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package stack;
2+
3+
public class ReverseAStackUsingRecursion {
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package stack;
2+
3+
import java.util.ArrayDeque;
4+
5+
public class ReverseStringUsingStack {
6+
public static void main(String[] args){
7+
ArrayDeque<Character> input = new ArrayDeque<>();
8+
String str = "ziuQskeeG";
9+
for(byte index=0;index<str.length();index++){
10+
input.push(str.charAt(index));
11+
}
12+
StringBuilder st = new StringBuilder();
13+
while(input.peek()!=null){
14+
15+
st.append(input.pop());
16+
}
17+
System.out.println(st);
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package stack;
2+
3+
public class ReverseStringWithoutStack {
4+
public static void main(String[] args){
5+
StringBuilder st = new StringBuilder("ziuQskeeG");
6+
for(int i=0;i<st.length()/2;i++){
7+
swap(st,i,st.length()-i-1);
8+
}
9+
System.out.println(st);
10+
}
11+
public static void swap(StringBuilder st,int index1,int index2){
12+
char temp = st.charAt(index1);
13+
st.setCharAt(index1,st.charAt(index2));
14+
st.setCharAt(index2,temp);
15+
}
16+
}

‎src/structure/LearnStack.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package structure;
2+
3+
import java.util.LinkedList;
4+
import java.util.PriorityQueue;
5+
import java.util.Queue;
6+
7+
public class LearnStack {
8+
public static void main(String[] args) {
9+
PriorityQueue<Integer> pq = new PriorityQueue<>();
10+
pq.add(20);
11+
pq.add(10);
12+
pq.add(50);
13+
System.out.println(pq);
14+
15+
PriorityQueue<String> pq1 = new PriorityQueue<>();
16+
pq1.add("Hello");
17+
pq1.add("ABC");
18+
pq1.add("Test");
19+
System.out.println(pq1);
20+
21+
Queue<Integer> q1 = new LinkedList<>();
22+
q1.add(20);
23+
q1.add(10);
24+
System.out.println(q1);
25+
}
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.