kumarasvn
- 38
0of 0 votes
AnswersGiven an array [a1b2c3d4] convert to [abcd1234] with 0(1) space and O(n) time
- kumarasvn on October 02, 2012 in India Edit | Report Duplicate | Flag
Microsoft Software Engineer / Developer - 10
0of 0 votes
AnswersHow will u find cube root of a number in efficient way?
- kumarasvn on June 20, 2011 Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm - 10
0of 0 votes
AnswersWrite a java code to find the second minimum element in an array using single loop.
- kumarasvn on May 22, 2011 Edit | Report Duplicate | Flag
Zycus Software Engineer / Developer Arrays - 7
0of 0 votes
Answers1) An array contains a set of +ve and –ve numbers. Find the number that is nearest to zero. If two numbers are equally near (like 2 and -2) then return +ve number.
- kumarasvn on May 22, 2011 Edit | Report Duplicate | Flag
Zycus Software Engineer / Developer Arrays - 3
0of 0 votes
AnswersIdentify the duplicates from a given array and remove them efficiently
- kumarasvn on May 22, 2011 Edit | Report Duplicate | Flag
Pega Software Engineer / Developer Arrays - 18
0of 0 votes
AnswersGiven a binary tree convert it into double linked list
eg:A B C D E F Goutput should be A B C G F E D or A C B D E F G
- kumarasvn on May 22, 2011 Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Trees and Graphs - 4
0of 0 votes
AnswersGiven a postfix expression convert into infix expression.
- kumarasvn on May 22, 2011 Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Data Structures
public static int search(int a[], int l, int u, int x) {
while (l <= u) {
int m = (l + u) / 2;
if (x == a[m]) {
return m;
} else if (a[l] <= a[m]) {
if (x > a[m]) {
l = m+1;
} else if (x >=a [l]) {
u = m-1;
} else {
l = m+1;
}
}
else if (x < a[m]) u = m-1;
else if (x <= a[u]) l = m+1;
else u = m - 1;
}
return -1;
}
This is working perfectly guys....
import java.util.Arrays;
public class FindNeartoZero {
public static void main(String[] args) {
int a[]={-10,-20,-30,-10,-50,-1,1};
Arrays.sort(a);
int i;
for(i=0;i<a.length;i++)
{
if(a[i]>0)
{
if(i==0)
{
System.out.println(a[i]);
System.exit(0);
}
int k=a[i-1];
System.out.println(Math.abs(k)<Math.abs(a[i])?k:a[i]);
System.exit(0);
}
}
if(i==a.length)
System.out.println(a[--i]);
}
}
Hi Sparky,
Even i lost there but i find out another solution for finding where the loop is starting.
1)First find the meeting point using slow and fast pointers
2)Find out the number of elements present in the loop(say n nodes)
3)Find out the nth node from last(Starting from meeting point) that nth node become the start of the loop.

superrrrrr... thanks dude...
- kumarasvn on June 20, 2011 Edit | Flag View Reply