In the first coding question, he using array hashing and character ASCII value, since it was mentioned that we only have lowercase characters, so the person created a array of size 26 to denote the each character index values. He was substracting a because ASCII range for 65-90(a-z), so the hash array would look something like int [] hashArray = {0,0,0,......0} , 26 zeros on each index. Now when he gets the index of each char by substracting a. For example if we want index of b, it will be 66-65 = 1 and then incrementing the value at that index, after computation he would have an array in which index have count of the characters. Now he could easily iterate through the array for each character and find if count of the char is 1 then return the index else if not found return -1;
this is first question of answer String sentence = "abcdcaf"; for (int i = 0; i < sentence.length(); i++) { int count = 0; for (int j = 0; j < sentence.length(); j++) { if (sentence.charAt(i) == sentence.charAt(j)) { count = count + 1; } } if (count == 1) { System.out.println(sentence.charAt(i)); break; } }
In the first coding question, he using array hashing and character ASCII value, since it was mentioned that we only have lowercase characters, so the person created a array of size 26 to denote the each character index values. He was substracting a because ASCII range for 65-90(a-z), so the hash array would look something like int [] hashArray = {0,0,0,......0} , 26 zeros on each index. Now when he gets the index of each char by substracting a. For example if we want index of b, it will be 66-65 = 1 and then incrementing the value at that index, after computation he would have an array in which index have count of the characters.
Now he could easily iterate through the array for each character and find if count of the char is 1 then return the index else if not found return -1;
👍
String str = "abcdcaf";
Map map = new HashMap();
for(int i=0; i
Iterate the string
If (str.indexOf(str.charAt(i)) == str.lastIndexOf(str.charAt(i)))
Return the character.
Once the loop finishes, return -1.
Can you please make vedio on Deloitte techno manegeral round for java developers
How much package you had got from deloitte after 2 years exp.
11 LPA
How many rounds of interview you had buddy?
Use Streams if you are using 1.8
👍👍🙌
Current interview Questions??
Yes bro. And u can see this video also th-cam.com/video/_byMXtfsmxY/w-d-xo.html
This is a real interview?
public class Practise {
public static int method1(String str) {
String s1=str;
int count=0;
int num=0;
for(int i=0;i
He got selected or not?
Selected
Bro is using chatgpt😂
This is real interview of Deloitte?
Yes buddy
@@krishnakantsharma2201 ok buddy. Continue upload this type videos
this is first question of answer
String sentence = "abcdcaf";
for (int i = 0; i < sentence.length(); i++) {
int count = 0;
for (int j = 0; j < sentence.length(); j++) {
if (sentence.charAt(i) == sentence.charAt(j)) {
count = count + 1;
}
}
if (count == 1) {
System.out.println(sentence.charAt(i));
break;
}
}
🙌🙌👍
so what about the return statement and the lowercase issues..
public class FirstNonRepeatingCharacter {
public static int firstNonRepeatingCharacter(String str) {
Map frequencyMap = str.chars()
.mapToObj(c -> (char) c)
.collect(Collectors.groupingBy(c -> c, LinkedHashMap::new, Collectors.counting()));
Optional firstNonRepeatingChar = frequencyMap.entrySet()
.stream()
.filter(entry -> entry.getValue() == 1)
.map(Map.Entry::getKey)
.findFirst();
return firstNonRepeatingChar.map(c -> str.indexOf(c)).orElse(-1);
}
public static void main(String[] args) {
String input = "abcdcafb";
int result = firstNonRepeatingCharacter(input);
System.out.println(result);
}
}