steelrahul
BAN USER- 0of 0 votes
AnswerImplement Java Set using TDD
- steelrahul in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 2of 2 votes
AnswersGiven a sorted array with only 0's and 1's.Count the number of 0's.
- steelrahul in India for Hyderabad
e.g: 0 0 0 0 1 1
Ans: 4.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 2of 2 votes
AnswersGiven n (of size m) Linked lists
- steelrahul in India for Hyderabad
Print all set(head of linked list) of link list that intersect with each other.
e.g.
1-->2-->3-->4-->5
6-->7-->8-->4-->5
8->9->10->11->12
13->14->15->12
16->17->18
1 6
8 13
16| Report Duplicate | Flag | PURGE
Amazon SDE1
public class MinVal {
static int[] a={0,0,0,0,0,1};
public int returnCount(int arr[],int low,int high) {
if(high >=low) {
int mid = (low+high)/2;
//System.out.println(mid);
if(mid == 0 && a[mid]==0) {
return mid+1;
}
if((mid == 0 || a[mid-1]==0)&& a[mid]==1) {
return mid;
}
if (a[mid]==1) {
return returnCount(arr,low,mid-1);
} else {
return returnCount(arr,mid+1,high);
}
}
return -1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MinVal minVal = new MinVal();
int mid = minVal.returnCount(a, 0, a.length-1);
System.out.println(mid);
}
}
- steelrahul July 25, 2015