Professional Documents
Culture Documents
*;
int i = 0;
while (i < len) {
// 3 4 -1 1
// -1 4 3 1
// 0 4 3 1. i = 1
// 0 1 3 4 i = 1
// 1 0 3 4. i = 1
int currentNumber = nums[i];
System.out.println("Current Number = " + currentNumber + " i = " + i);
if (isValidNumber(currentNumber, len)) {
if (currentNumber == (i-1)) {
i++;
} // the number is already in the right location.
else {
// swap(nums[currentNumber-1], nums[i]);
nums[i] = nums[currentNumber-1];
// #2: -1 -2 -3 -9
// 1
// #3: 1 2 3 4
// 5
// #5: 1 5 3 4 => 1 3 4 5
// 2
// InputArray: 3 4 -1 1
// InputArray: -1 4 3 1
// InputArray: - 4 3 1
// InputArray: - 1 3 4
// InputArray: 1 - 3 4
// // - Get to a point where you can explain your approach to a 10 year old
// - Take the number, and insert it in the appropriate index
// - If there is a number in that index already (in the forward motion), swap the numbers.
// - Don't move the current pointer.
// - If the current number fits in the right index or its an useless number, then discard and
move forward.
// - Find the gap where there is no number.
// // - Take a stab at the high level logic & write it down.
// len = sizeof(inputArray);
// maxOutput = len + 1;
// invalidNumbers: anything <= 0; anything > len;
// - Try to offload processing to functions & keeping your main code small.
// Milestone 3: Code by expanding your pseudocode
// - Make sure you name the variables, functions clearly.
// - Avoid constants in your code unless necessary; go for generic functions, you can use
examples for your thinking though.
// - Use libraries as much as possible
// Milestone 4: Prove to the interviewer that your code works with unit tests
// - Make sure you check boundary conditions
// Time & storage complexity
// Suggest optimizations