Jodo | SDE-2 | Bangalore
Anonymous User
344
Jun 01, 2023
Jun 04, 2023

Interview was conducted by interview vector.

Q1. https://leetcode.com/problems/two-sum/

class Solution {
    public int[] twoSum(int[] nums, int target) {
        //[2,7,11,15]
        Map<Integer, Integer> numToIndex = new HashMap<>();
        numToIndex.put(nums[0], 0);//{2=0,}

        for(int i=1;i<nums.length;i++){//{2=0,}
            int k = target - nums[i];//9-7 = 2
            if(numToIndex.containsKey(k)){//{2=0,}
                return new int[]{numToIndex.get(k),i};
            }
            numToIndex.put(nums[i], i);
        }
        return new int[]{-1,-1};
    }
}

Q2. https://leetcode.com/problems/count-sub-islands/

class Solution {
    public int countSubIslands(int[][] grid1, int[][] grid2) {
        int count = 0;
        for(int i=0;i<grid2.length;i++){
            for(int j=0;j<grid2[i].length;j++){
                if(grid2[i][j]==1){
                    //System.out.println("I :"+i+" J :"+j);
                    boolean isSubIsland = true;
                    if(grid1[i][j]!=1){
                        isSubIsland = false;
                    }
                    //if this is not subIsland mark entire island in grid2 visited.
                    boolean isAdjSubIsland = markVisited(grid1, grid2, i, j, grid2.length, grid2[i].length);
                    isSubIsland = (isSubIsland && isAdjSubIsland);
                    if(isSubIsland){
                        count++;
                    }
                }
                
            }
        }
        return count;
    }

    private static int[] ROW = {-1,+1,0,0};
    private static int[] COL = {0,0,-1,+1};

    private boolean markVisited(int[][] grid1, int[][] grid2, int x, int y, int m, int n){
        grid1[x][y] = 0;
        grid2[x][y] = 0;

        boolean isSubIsland = true;

        for(int i=0;i<4;i++){
            int newX = x+ROW[i];
            int newY = y+COL[i];
            if(newX>=0 && newX<m && newY>=0 && newY<n && grid2[newX][newY]==1){
                if(grid1[newX][newY]!=1){
                    isSubIsland = false;
                }
                boolean isAdjSubIsland = markVisited(grid1, grid2, newX, newY, m ,n);
                isSubIsland = (isAdjSubIsland && isSubIsland);
            }
        }
        return isSubIsland;
    }
}

Q3. ACID Properties
Q4. What is ORM

Conclusion: The interview felt poitive but was REJECTED ultimately.

Comments (0)