Skip to content

Commit b39d314

Browse files
committed
Added more coding assessments and their solutions
Updated package structure
1 parent e3d5ac0 commit b39d314

30 files changed

+1136
-661
lines changed

InterviewsPreparation/.classpath

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" output="target/classes" path="src/main/java">
3+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
44
<attributes>
55
<attribute name="optional" value="true"/>
66
<attribute name="maven.pomderived" value="true"/>
77
</attributes>
88
</classpathentry>
9-
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
9+
<classpathentry kind="src" output="target/classes" path="src/main/java">
1010
<attributes>
1111
<attribute name="optional" value="true"/>
1212
<attribute name="maven.pomderived" value="true"/>

InterviewsPreparation/.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>InterviewsPreparation</name>
3+
<name>Interviews-Preparation</name>
44
<comment></comment>
55
<projects>
66
</projects>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.ip.ca;
5+
6+
import java.util.Scanner;
7+
8+
/**
9+
* @author Kanahaiya Gupta
10+
*
11+
*/
12+
public class TheLightStore {
13+
14+
private static int getOpCount(String str1, String str2) {
15+
int dp[][] = new int[str1.length() + 1][str2.length() + 1];
16+
for (int i = 0; i <= str1.length(); i++) {
17+
for (int j = 0; j <= str2.length(); j++) {
18+
if (i == 0)
19+
dp[i][j] = j;
20+
else if (j == 0)
21+
dp[i][j] = i;
22+
else if (str1.charAt(i - 1) == str2.charAt(j - 1))
23+
dp[i][j] = dp[i - 1][j - 1];
24+
else {
25+
dp[i][j] = 1 + Math.min(dp[i - 1][j], Math.min(dp[i][j - 1], dp[i - 1][j - 1]));
26+
}
27+
}
28+
}
29+
return dp[str1.length()][str2.length()];
30+
}
31+
32+
public static void main(String args[]) throws Exception {
33+
Scanner sc = new Scanner(System.in);
34+
String input = sc.next();
35+
String output = sc.next();
36+
int result = getOpCount(input, output);
37+
System.out.println(result);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
/**
2-
*
3-
*/
4-
package com.javaaid.interviews.preparation.cleartrip;
5-
6-
import java.util.Scanner;
7-
8-
/**
9-
* @author Kanahaiya Gupta
10-
*
11-
*/
12-
public class StringChain {
13-
14-
static int charCount = 0;
15-
16-
public static void main(String[] args) {
17-
Scanner sc = new Scanner(System.in);
18-
/*int N = sc.nextInt();
19-
String words[] = new String[N];
20-
for (int i = 0; i < N; i++) {
21-
words[i] = sc.next();
22-
}*/
23-
String[] words = new String[]{"a", "b","ba", "bca", "bda", "bdca"};
24-
25-
int result = calulateLongestChain(words);
26-
System.out.println(result);
27-
sc.close();
28-
}
29-
30-
/**
31-
* @param words
32-
* @return
33-
*/
34-
private static int calulateLongestChain(String[] words) {
35-
int maxLongestChainOfCharacter = 0;
36-
for (String word : words) {
37-
int currentCharCount= findMaxChain(words, word, 0);
38-
maxLongestChainOfCharacter = Math.max(maxLongestChainOfCharacter, currentCharCount);
39-
40-
}
41-
return maxLongestChainOfCharacter;
42-
}
43-
44-
/**
45-
* @param word
46-
* @return
47-
*/
48-
private static int findMaxChain(String[] words, String word, int lenCounter) {
49-
if (!wordsContains(words, word)) {
50-
return 0;
51-
}
52-
lenCounter++;
53-
charCount = lenCounter;
54-
for (int i = 0; i < word.length(); i++) {
55-
StringBuilder sb = new StringBuilder(word);
56-
sb.delete(i, i + 1);
57-
findMaxChain(words, sb.toString(), lenCounter);
58-
}
59-
return charCount;
60-
}
61-
62-
/**
63-
* @param string
64-
* @return
65-
*/
66-
private static boolean wordsContains(String[] words, String string) {
67-
for (String word : words) {
68-
if (word.equals(string)) {
69-
return true;
70-
}
71-
}
72-
return false;
73-
}
74-
75-
}
1+
/**
2+
*
3+
*/
4+
package com.javaaid.ip.cleartrip;
5+
6+
import java.util.Scanner;
7+
8+
/**
9+
* @author Kanahaiya Gupta
10+
*
11+
*/
12+
public class StringChain {
13+
14+
static int charCount = 0;
15+
16+
public static void main(String[] args) {
17+
Scanner sc = new Scanner(System.in);
18+
/*int N = sc.nextInt();
19+
String words[] = new String[N];
20+
for (int i = 0; i < N; i++) {
21+
words[i] = sc.next();
22+
}*/
23+
String[] words = new String[]{"a", "b","ba", "bca", "bda", "bdca"};
24+
25+
int result = calulateLongestChain(words);
26+
System.out.println(result);
27+
sc.close();
28+
}
29+
30+
/**
31+
* @param words
32+
* @return
33+
*/
34+
private static int calulateLongestChain(String[] words) {
35+
int maxLongestChainOfCharacter = 0;
36+
for (String word : words) {
37+
int currentCharCount= findMaxChain(words, word, 0);
38+
maxLongestChainOfCharacter = Math.max(maxLongestChainOfCharacter, currentCharCount);
39+
40+
}
41+
return maxLongestChainOfCharacter;
42+
}
43+
44+
/**
45+
* @param word
46+
* @return
47+
*/
48+
private static int findMaxChain(String[] words, String word, int lenCounter) {
49+
if (!wordsContains(words, word)) {
50+
return 0;
51+
}
52+
lenCounter++;
53+
charCount = lenCounter;
54+
for (int i = 0; i < word.length(); i++) {
55+
StringBuilder sb = new StringBuilder(word);
56+
sb.delete(i, i + 1);
57+
findMaxChain(words, sb.toString(), lenCounter);
58+
}
59+
return charCount;
60+
}
61+
62+
/**
63+
* @param string
64+
* @return
65+
*/
66+
private static boolean wordsContains(String[] words, String string) {
67+
for (String word : words) {
68+
if (word.equals(string)) {
69+
return true;
70+
}
71+
}
72+
return false;
73+
}
74+
75+
}

0 commit comments

Comments
 (0)