Flexport | SDE (2) | Bengaluru | April 2024 | [Reject]
Anonymous User
2018

Current experience:

Education: 2021 Grad, IIIT College
Position: SDE1 at Fintech
Location: Bengaluru, IN

Interview experience:

Applied Position: SDE2 at Flexport
Location: Bengaluru, IN
Date: April, 2024

Round 1: Technical [1 hour]

Question:
Consider an infinite grid. There are two types of queries,

  1. A letter will drop from top (in a column) and settle at the bottom (or above a already present letter)
  2. Return TRUE, if there are three same letter in any column, else return FALSE.

Follow-up 1:

  1. Return TRUE, if there are three same letter in any column, else return FALSE.
  2. Return TRUE, if there are three same letter in any row, else return FALSE.

Follow-up 2:

  1. Return TRUE, if there are three same letter in any column, else return FALSE.
  2. Return TRUE, if there are three same letter in any row, else return FALSE.
  3. Return TRUE, if there are three same letter in any diagonal, else return FALSE.

Follow-up 3:
Extend the "Follow-up 2" to match N (not just 3) letter.

My Solution:

===================================
Board Class
===================================


package Board;

import Game.Disc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class GridBoard {

    HashMap<Integer, List<Disc>> board;
    Integer NumberOfMatches;

    public GridBoard(Integer N) {
        NumberOfMatches = N;
        board = new HashMap<>();
    }

    public boolean put(Integer column, Disc disc) {
        // Check for empty column
        if (!board.containsKey(column)) {
            board.put(column, new ArrayList<>());
        }

        // Put the disc in given column
        board.get(column).add(disc);

        if (isWinningMoveLastNColumn(column, disc)) {
            System.out.println("Game finished with Column match!");
            return true;
        } else if(isWinningMoveLastNRow(column, disc)) {
            System.out.println("Game finished with Row match!");
        } else {
            System.out.println("Next Player turn!!!");
        }
        return false;
    }

    private boolean isWinningMove(Integer column, Disc disc) {
        List<Disc> discs = board.get(column);

        int discsSize = discs.size();

        if (discsSize < 3 || !(discs.get(discsSize-1)==discs.get(discsSize-2) && discs.get(discsSize-2)==discs.get(discsSize-3)))
            return false;

        return true;
    }

    private boolean isWinningMoveLastNColumn(Integer column, Disc disc) {
        List<Disc> discs = board.get(column);

        int discsSize = discs.size();

        if (discsSize < NumberOfMatches)
            return false;

        // 5 elements, N = 3
        // 0, 1, 2, 3, 4 => Check for 2, 3, 4
        for (int i = discsSize-2; i >= discsSize - NumberOfMatches; --i) {
            if (discs.get(discsSize-1) != discs.get(i))
                return false;
        }
        return true;
    }

    private boolean isWinningMoveLastNRow(Integer column, Disc disc) {
        List<Disc> discs = board.get(column);

        int currRow = discs.size();
        int totalMatches = 1;
        int leftColumn = column-1;

        while (board.containsKey(leftColumn)) {
            List<Disc> leftColumnDisc = board.get(leftColumn);

            if (leftColumnDisc.size() < currRow || leftColumnDisc.get(currRow-1) != disc)
                break;

            ++totalMatches;
            if (totalMatches >= NumberOfMatches)
                break;

            leftColumn--;
        }

        int rightColumn = column+1;
        while (board.containsKey(rightColumn)) {
            List<Disc> rightColumnDisc = board.get(rightColumn);

            if (rightColumnDisc.size() < currRow || rightColumnDisc.get(currRow-1) != disc)
                break;

            ++totalMatches;
            if (totalMatches >= NumberOfMatches)
                break;

            rightColumn++;
        }

        return (totalMatches >= NumberOfMatches);
    }

}


===================================
Disc ENUM
===================================


package Game;

public enum Disc {
    R,
    G,
    B,
    W,
    Y;
}



===================================
Main Class
===================================

import Board.GridBoard;
import Game.Disc;

public class Main {

    /*
                      R
                B     R  B
             R     B  R  R  B
      -  -  -  -  -  -  -  -  -
...  -3 -2 -1  0  1  2  3  4  5  ...
     */
    public static void main(String[] args) {
        System.out.println("Connection Board Game!");

        GridBoard gridBoard = new GridBoard(4);

        // Starting game
        gridBoard.put(-2, Disc.Y);
        gridBoard.put(-3, Disc.R);
        gridBoard.put(-1, Disc.R);
        gridBoard.put(0, Disc.R);
        gridBoard.put(0, Disc.Y);
        gridBoard.put(-1, Disc.Y);
        gridBoard.put(-2, Disc.Y);
        gridBoard.put(-3, Disc.B);
        gridBoard.put(2, Disc.R);
        gridBoard.put(1, Disc.R);

        // TC: O(N) , where N is number of matches
    }
}

Verdict: Moved to next round

Round 2: Project Discussion + LLD [1 hour]

  1. Discussed first 30 mins on any project doing in current job.
    Note: They were looking for something you've build from scratch in your organisation (for ex, writing code for MOON Landing mission).

  2. Design Chess Validator.
    Focus Ares: Use best design principles, Modular code, etc.

Verdict: Moved to next round

Round 3: Managerial round + HLD [1 hour]

  1. A few question on current work experience, projects, and technical aspects.

  2. Design Notification Scheduler.
    Focus Ares: Use best technologies, describe about each component.

Verdict: Interviewer didn't seem to be happy, maybe they're looking for more work experience.

Result: After a week, received rejection mail. No feedback on which round went well or not well.

Comments (2)