Flipkart Interview Question for Software Engineer / Developers






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

cant we use KMP to process each of string tokens ...the complexity will be O(m*n) where n is length of string and m is count of total no of tokens

- ankur September 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use STL map..

- Anonymous September 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can u explain it further??

- jango September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. split given string by space dilimiter
2. Put each string in hashtable like key=string, value=count
3. Now check each given array of tokens against hashtable and get the counts

Let me know if you need code..

- Praveen October 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This does not sound correct. The second parameter is what is giving the tokens. So we can use each token from the second param list and split the first param text and then store the array size into the hashmap where key = delimiter and value = count

- Anu October 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.HashMap;
import java.util.Map;


public class StringTokens {
	private static String [] tokens = {"This", "is", "boy"} ;
	private static String text = "this is the new tech this boy and where is this boy and there is this boy";
	
	public static void main(String [] args) {
		printTokenCount();
	}
	
	public static void printTokenCount() {
		//tokenize the text
		String [] tokenized = text.split(" ");
		
		Map<String,Integer> tokenMap = new HashMap<String,Integer>();
		
		for (String s: tokenized) {
			if (!tokenMap.containsKey(s)) {
				tokenMap.put(s, new Integer(1));
			} else {
				int count = tokenMap.get(s);
				tokenMap.put(s, ++count);
			}
		}
		
		for (String s: tokens) {
			s=s.toLowerCase();
			if (tokenMap.containsKey(s)) {
				int count = tokenMap.get(s);
				System.out.println(s + " : " + count);
			}
		}
	}
}

- bawet October 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@bawet, your answer is wrong because as per question. if the token is "is" and string is:"this is the new tech".
Then "is" appears twice in string once in "this" and then in "is"
Please correct your solution.

- Anil December 27, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@bawet, your answer is wrong because as per question. if the token is "is" and string is:"this is the new tech".
Then "is" appears twice in string once in "this" and then in "is"
Please correct your solution.

- Anil December 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class test {
private static String [] tokens = {"This", "is", "boy"} ;
private static String text = "this is the new tech this boy and where is this boy and there is this boy";
public static void main(String[] args) {
for(String s : tokens)
{
System.out.print("\ntoken "+s);
String[] tokens1 = text.split(s);
System.out.print("\tcount " + tokens1.length);
}
}
}

- Bharath Varma December 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.util.HashSet;

public class CountOccurs{
public static void main(String[] args) {

String strarr[] = { "pras", "ram","vino","pras","pras"};
String str="pras";
CountOccurs oc= new CountOccurs();
System.out.println("The string occurs"+oc.count(str,strarr));
}
public int count(String str, String []strarr){
int i=0;

List text=Arrays.asList(strarr);
int count=0;
for(i=0;i<text.size();i++){
if(text.get(i).equals((str))){
count++;
}
}


return count;
}
}


This is my understanding...

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

use stringTokenizer

- akshay dange February 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

stringTokeniser is going to deprecate.use String.split();

- Anonymous March 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String.split() will not work for the case "fofofofof" and token is "fo".. in this case the array will have only one element empty_string.

- iamnotiam April 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@iamnotiam You are wrong. The split code will work. Please see my below posting about the code and output. The output of split command will basically contain 4 empty strings and 1 string with "f". So array length - 1 will return the correct count

- Harish June 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey54200" class="run-this">public class Test{
public void go(){
String s = "fofofofof";
String[] s1 = s.split("fo");
for(String a : s1)
System.out.println("Token = #"+a+"#");
System.out.println("Total Number of Tokens = "+s1.length);
}
public static void main(String... args){
Test t = new Test();
t.go();
}
}
/*
Output
======
Token = ##
Token = ##
Token = ##
Token = ##
Token = #f#
Total Number of Tokens = 5
*/</pre><pre title="CodeMonkey54200" input="yes">
</pre>

- Anonymous June 27, 2011 | 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