is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
Below code is perfect. we must reset the head to i but at the same time we need to take care of the tail. a few manipulations to the code written by Riku will give us the result. Anyways credit goes to riku.
- Rrakshith007 May 28, 2015public class ss {
public static void getMaxLength(int[] arr) { int leng = arr.length;
int maxCount = 0;
for(int i=0;i<leng;i++) {
int len=arr.length;
int head = i; int tail = len-1;
int max = 0; // Max value of smaller sub-array
int min = Integer.MAX_VALUE; // Min value of larger sub-array
int currentCount = 0; // Max length sub-array for elements starting at index i
int startMax = -1; // 1 = head represents larger sub-array ; 2 = tail represents larger sub-array
while(tail > head) {
if(startMax == -1)
startMax = arr[head] > arr[tail] ? 1 : 0;
else {
if((startMax == 1) && ((arr[head] < arr[tail]) || (arr[head] < max) || (arr[tail] > min))) {
startMax = -1; max = 0; min = Integer.MAX_VALUE; head = i; len--;tail=len;
currentCount = 0;
continue;
}
else if((startMax == 0) && ((arr[head] > arr[tail]) || (arr[head] > min) || (arr[tail] < max))) {
startMax = -1; max = 0; min = Integer.MAX_VALUE; head = i; len--;tail=len;
currentCount = 0; continue;
}
}
max = (startMax == 1) ? Math.max(max, arr[tail]) : Math.max(max, arr[head]);
min = (startMax == 1) ? Math.min(min, arr[head]) : Math.min(min, arr[tail]);
head++; tail--; currentCount++;
maxCount = (currentCount >= maxCount) ? currentCount : maxCount;
}
}
System.out.println("Max Length = " + maxCount);
}
public static void main(String[] args) {
getMaxLength(new int[] {6, 50, 7, 35, 1, 2, 3, 8, 45, 5, 30, 40, 41, 60, 4 }); // Expected 4
}
}