Yatra.com Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Using a bitmap takes one pass of the array to find this

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

I guess...you could do it using binary search tree(or set if u wanted to use inbuild lib) with total complexity < O(n) ~ O(lg n)

Lets take two variables as
first_non_repetative=-infinity and second_non_repetative=-inifinity

take one element at a time and try to insert it in a binary search tree..so now if at any moment you get a collision(get same data in BST) (for a no say x)then don't insert it rather do
if(first_non_repetative == -infinity)
{
first_non_repetative = x;
}

else if(first_non_repetative!=x && second_non_repetative==-infinity)
{
second_non_repetative = x
return ///that would be the ans
}

- raja roy January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

PSEUDO CODE
=================
1) Iterate through elements of the array from the beginning and put them in hash table, key being array element and 1 as the value
2) If the next value in the array is already there , increase the value of that key by 1
3) Once all the array elements are added in hash table, iterate the array again from the beginning to find the value of each key.
4) Find the second key whose value is 1.

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

import java.io.*;
public class str1
{
public static void main(String a[])
{
int[] ar={3,4,3,4,4,3,2,4,1,9,8};
int[] a1=new int[100];
int i,c=1,j,f=0,m=0,k=0;
for(i=0;i<11;i++)
{ c=1;
for(j=i+1;j<11;j++)
{
for(k==0;k<11;k++)
{
if(ar[i]==ar[j]&&ar[j]!=a1[k])
{
c++;
k++;
}
}
if(c!=1)
a1[k]=ar[i];
System.out.println("the c is"+c);
System.out.println("the no is"+a1[k]);
if(c==1)
f++;
if(f==2)
m=ar[i];
}
System.out.println("the 2nd no is"+m);
}
}

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

Use a LinkedHashMap. Insert elements from array in this map.Elements inserted in the HashMap will be in insertion order. Iterate the map and chose the 2nd element with frequency 1.

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

BST is good, since its basic. Using HashMap will give better performance.

- Anonymous May 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a linkedhashmap to count the frequency of each element.

- Ankit Jain October 16, 2014 | 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