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.
import java.util.Arrays;
- sswaroop4 October 09, 2012public class ArraysSum {
public void arraySum(int[] arr){
int arraySize=arr.length;
int[] tmparr=new int[arraySize];
System.arraycopy(arr,0,tmparr,0, arr.length);
Arrays.sort(tmparr);
// getting another array with the sorted positions list
for(int i=arraySize-1;i>=0;i--){
int search=tmparr[i];
for(int j=0;j<arraySize;j++){
if(arr[j]==search){ tmparr[i]=j;break;}
}
}
System.out.println("Sortedpositions - array");
for(int j=0;j<arraySize;j++)
System.out.println(tmparr[j]+"-"+arr[j]);
//calculating the sum depending on the positions in tmparr array
int sum=arr[tmparr[arraySize-1]],prevPos=tmparr[arraySize-1];
System.out.println(sum);
for(int i=arraySize-2;i>=0;i--)
{
if(tmparr[i]!=prevPos+1 && tmparr[i]!=prevPos-1)
{
sum+=arr[tmparr[i]];
prevPos=tmparr[i];
}
}
System.out.println(sum);
}
public static void main(String args[]){
ArraysSum as=new ArraysSum();
int[] arr={1,4,3,5,9,23,2};
as.arraySum(arr);
}
}