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.
public static void main(String[] args) {
- Rajeev krishna singh December 29, 2021int[] arr = {7, 5, 6, 3, 4, 1, 2, 9, 11};
ArrayOperations arrayOperations = new ArrayOperations();
int[] res = arrayOperations.replaceElementsWithNextGreat(arr);
for (int i = 0; i < res.length; i++) {
System.out.print(res[i] + " ");
}
}
/**
* <p>Replace element of an Array with nearest bigger number at right side of the Array in O(n)
* <br>For example if the input Array is
* <br>7, 5, 6, 3, 4, 1, 2, 9, 11
* <br>output array should be
* <br>9, 6, 9, 4, 9, 2, 9, 11, 11</p>
*
* @param arr
* @return
*/
public int[] replaceElementsWithNextGreat(int[] arr) {
int n = arr.length;
int[] result = new int[n];
Stack<Integer> st = new Stack<>();
for (int i = n - 1; i >= 0; i--) {
while (!st.isEmpty() && arr[i] >= st.peek()) //try to find > a[i] element
st.pop();
if (st.isEmpty())
result[i] = arr[i]; //nothing > a[i] to right (or use a[i] instead of INF)
else
result[i] = st.peek(); //this was > a[i] to right
st.push(arr[i]);
}
return result;
}