Kasheruka Interview Question for SDE-2s


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

#Language: Python
s = "Hello world Please"
refString = "Help"
print({i:s.count(i) for i in refString if i in s})

- Anonymous June 03, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Online Java Compiler
// Use this editor to write, compile and run your Java code online

HelloWorld {
public static void main(String[] args) {

String s = "Hello world Please";
char[] ref = "Help".toCharArray();
for(char e: ref){
String val = s.replaceAll(" ", "");
int count= val.length();
String removeCount = val.replaceAll(Character.toString(e), "");
int current = removeCount.length();
System.out.print(e+":"+ (count-current));
if(e != 'p'){
System.out.print(",");
}
}

}
}

- Johnpaul Raphel June 04, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

####Python
string1 = input("Enter Sentance : ").capitalize()
string2 = input("Enter Refrence String :").capitalize()
for i in string2:
if i in string1:
st3 = string1.count(i)
print({i:st3})

- Sagar Bhadauria June 20, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

####Java
public static void calcCharacters(String inputStr, String refStr) {
Map<Character, Integer> result = new HashMap<>();
inputStr.chars().filter(c -> refStr.indexOf(c) >= 0).forEach(c -> {
Character key = Character.valueOf((char) c);
result.computeIfPresent( key, (k, v) -> v+1);
result.putIfAbsent(key, 1);
});
result.entrySet().forEach( e -> System.out.println(e.getKey() + ": " + e.getValue()));
}

- w0t July 17, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void calcCharacters(String inputStr, String refStr) {
        Map<Character, Integer> result = new HashMap<>();
        inputStr.chars().filter(c -> refStr.indexOf(c) >= 0).forEach(c -> {
            Character key = Character.valueOf((char) c);
            result.computeIfPresent( key, (k, v) -> v+1);
            result.putIfAbsent(key, 1);
        });
        result.entrySet().forEach( e -> System.out.println(e.getKey() + ": " + e.getValue()));
    }

- w0t July 17, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
#print("Hello world")
a='Hello Hi'
b='Hi'
c=[]
for i in range(len(b)):
count=0
for j in range(len(a)):
if b[i]==a[j]:
count=count+1
c.append(count)
#print(c)
for i in range(len(b)):
print(b[i]+":",end="")
print(c[i])

- Anonymous January 29, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
#print("Hello world")
a='Hello Hi'
b='Hi'
c=[]
for i in range(len(b)):
count=0
for j in range(len(a)):
if b[i]==a[j]:
count=count+1
c.append(count)
#print(c)
for i in range(len(b)):
print(b[i]+":",end="")
print(c[i])

- Nawaz January 29, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Javascript

const inputStr = "Hello world please";
const refStr = "help";

[...refStr].forEach((element) => {
const reg = new RegExp(element, "gi");
const matchArr = inputStr.match(reg);
console.log(`char ${element} count is: ${matchArr.length}`);
});

- Binod Singh February 17, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
* Given a input string 'Hello World' and a input reference String, give count of each character (from refString) in the given string
Eg inputString: "Hello World Please", refString: "Help"
*
*/
public class RefStringCountInOriginal {


public static Map<Character,Integer> countRefCharInOriginal(String input, String ref){

Map<Character, Integer> charCountOriginal = new HashMap<>();

Map<Character, Integer> charCountFinal = new HashMap<>();

input = input.toLowerCase();
ref = ref.toLowerCase();

for(int i=0;i<input.toCharArray().length;i++) {

if(input.charAt(i) == ' ') {
continue;
}
if(!charCountOriginal.containsKey(input.charAt(i))){
charCountOriginal.put(input.charAt(i), 1);
}else {
charCountOriginal.put(input.charAt(i), charCountOriginal.get(input.charAt(i))+1);
}
}


for(int i=0;i<ref.toCharArray().length;i++) {
if(charCountOriginal.containsKey(ref.charAt(i))) {
charCountFinal.put(ref.charAt(i), charCountOriginal.get(ref.charAt(i)));
}
else {
charCountFinal.put(ref.charAt(i), 0);
}
}


return charCountFinal;

}

public static void main(String[] args) {

Map<Character, Integer> result = countRefCharInOriginal("Hello World Please", "Help");

result.entrySet().forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));
}

}

- Chiru March 04, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static Map<Character,Integer> countRefCharInOriginal(String input, String ref){

Map<Character, Integer> charCountOriginal = new HashMap<>();

Map<Character, Integer> charCountFinal = new HashMap<>();

input = input.toLowerCase();
ref = ref.toLowerCase();

for(int i=0;i<input.toCharArray().length;i++) {

if(input.charAt(i) == ' ') {
continue;
}
if(!charCountOriginal.containsKey(input.charAt(i))){
charCountOriginal.put(input.charAt(i), 1);
}else {
charCountOriginal.put(input.charAt(i), charCountOriginal.get(input.charAt(i))+1);
}
}


for(int i=0;i<ref.toCharArray().length;i++) {
if(charCountOriginal.containsKey(ref.charAt(i))) {
charCountFinal.put(ref.charAt(i), charCountOriginal.get(ref.charAt(i)));
}
else {
charCountFinal.put(ref.charAt(i), 0);
}
}


return charCountFinal;

}

- Chiru March 04, 2022 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More