脸熟实习

5分钟自我介绍,然后考了 https://leetcode.com/problems/insert-into-a-cyclic-sorted-list/

Was able to solve it in the required time and space complexity, but only finished with 5 minutes left in the interview.

我是直接做题,2道

Question 1: https://leetcode.com/problems/add-binary/

Question 2: https://leetcode.com/problems/number-of-islands/

报个我的
reverse an array for k distance.
[2,3,1,5,4] and k =3
output : [2,3,1,5,4]
method
void reverse(int[] arr, k)

this method will only reverse the array

write another method which will sort the array by incorporating reverse method inside sort.
sort(int[] arr)
{
//call reverse method
}

You must have to call reverse(arr,k) method to sort the array. You are not allowed to modify the reverse method
final out put [1,2,3,4,5], and this is inplace reverse and sorting

public void sort(int[] arr) {
    for(int x = arr.length; x > 1; x--) {
        int pos;
        for (pos = 0; arr[pos] != x; pos++);
        reverse(arr, pos);
        reverse(arr, x - 1);
    }
}