praneethreddy.bokka
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class n2uniqeandn2repeatsameElement {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[]= {1,2,3,4,1,1,1,1,5,6};
int i =0;
int l= a.length;
if(a[i]==a[l-1]||a[i]==a[l-2]||a[i+1]==a[l-1])
{
System.out.println( a[i]);
}
else
{
while(i+1<l)
{
if(a[i]==a[i+1])
{
System.out.println(a[i]);
break;
}
else
i++;
}
}
}
}
Comment hidden because of low score. Click to expand.
0
of 0 vote
yes either you should use peek() for both min and max or else you need to pop for both min and max together
- praneethreddy.bokka March 26, 2013Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
This would work only if the numbers are consecutive
- praneethreddy.bokka March 27, 2013