Persistent Systems Interview Question for Java Developers


Country: India
Interview Type: Written Test




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

// ZoomBA
input = ["ab", "cd", "f", "ab", "ef", "abc"]
println ( rindex  ( input , 'ab') )

- NoOne October 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

input = ["ab", "cd", "f", "ab", "ef", "abc"]

exp = /(\w*)ab(\w*)/

cnt = 0
input.each do |str|
    if !(str.match(exp))
        cnt += 1
    end
end

puts cnt

- Ruby February 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

input = ["ab", "cd", "f", "ab", "ef", "abc"]

exp = /(\w*)ab(\w*)/

cnt = 0
input.each do |str|
    if !(str.match(exp))
        cnt += 1
    end
end

puts cnt

- ruby February 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It's hard to understand the problem definition. Does the string we look for need to be at the beginning of the strings? What are we trying to optimize?
So, supposing that we are looking only for prefixes, `input[]` is huge and we are optimizing for the fast counting of prefixes, you could save `input` into a trie and keep in the trie nodes the amount of strings with this prefix.

- Leonid99 February 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String x,y;
		String[] a={"Ab", "cd", "f", "aB", "ef", "abc"};
		int i,j,count=0;
		Scanner s = new Scanner(System.in);
		System.out.println("Enter the String/Sub-string to be searched");
		x=s.nextLine();
		System.out.println("The String to be searched is: "+x);
		
		j= a.length;
		for(i=0;i<j;i++)
		{
			y=a[i];
			if(y.toLowerCase().contains(x.toLowerCase()))
			{
				count++;
			}
		}
		 
		System.out.println("There are "+count+" occurences in the given string");

- Neo February 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static long PrintOccurenceOfString(List<string> lstString, string word)
{
long occurence = 0;
if(lstString!=null && lstString.Any())
{
foreach (var item in lstString)
{
if (item.ToUpper().IndexOf(word.ToUpper()) > -1)
{
++occurence;
}
}
}
return occurence;
}

- Devendra Kumar June 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isn't Trie data structure the solution for it ?

- vinodjayachandran June 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int count=0;
for(int i=0;i<input.length;i++) {
if(input[i].startsWith("ab")) {
count++;
}
}

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

import java.util.regex.*;
import java.util.*;
class Demo
{
public static void main(String args[])
{
String input[]={"ab","cd","f","ab","ef","abc"};
Scanner scan=new Scanner(System.in);
System.out.println("ENTER STRING WHICH U WANT TO SEARCH:");
String search=scan.next();
Pattern p=Pattern.compile(search);
int count=0;
for(String str:input)
{
Matcher m=p.matcher(str);
while(m.find())
{
count++;
}
}
System.out.println("OCCURENCE OF GIVEN STRING:"+count);
}
}

- Mazahar December 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.regex.*;
import java.util.*;
class Demo
{
public static void main(String args[])
{
String input[]={"ab","cd","f","ab","ef","abc"};
Scanner scan=new Scanner(System.in);
System.out.println("ENTER STRING WHICH U WANT TO SEARCH:");
String search=scan.next();
Pattern p=Pattern.compile(search);
int count=0;
for(String str:input)
{
Matcher m=p.matcher(str);
while(m.find())
{
count++;
}
}
System.out.println("OCCURENCE OF GIVEN STRING:"+count);
}
}

- Mazahar December 11, 2016 | 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