← Deloitte bank

Deloitte · Question 35 · Arrays

Valid Sudoku

ArraysJavacode⏱ O(1)💾 O(1)
Service-based

Problem

Check rows, columns, and 3x3 boxes for duplicates using boolean markers.

Approach

Track seen digits per row, column and box.

Time O(1)Space O(1)

How it works

  1. 1Mark each digit in its row, column and box.
  2. 2A repeat mark fails immediately.

Sample input / output

Input:
board = standard valid 9x9 puzzle
Output:
true

Constraints

9x9 board; validity of filled cells only.

Solution — read it, then walk it

Time O(1)Space O(1)Loops 2Branches 2Returns 1source · Java
Scroll sideways for wide charts — the view follows the active step.
↻ repeat↻ repeatSTARTimport java.util.*DEFINE class MainDEFINE static booleanisValidSudoku(char[][]board)DEFINE [][] row = newboolean[9][9], col = newboolean[9][9], box = ne…for (int i = 0; i < 9;i++)for (int j = 0; j < 9;j++)if (board[i][j] =='.') continueDEFINE num = board[i][j] -'1', b = (i / 3) * 3 + j /3if (row[i][num] ||col[j][num] ||box[b][num]) retur…row[i][num] = col[j][num] =box[b][num] = trueRETURN trueDEFINE static voidmain(String[] args)DEFINE [][] board ={'5','3','.','.','7','.','.','.','.'},{'6','.','.','1','9','5','.','.','.'},{'.','9','8','.','.','.','.','6','.'},{'8','.','.','.','6','.','.','.','3'},{'4','.','.','8','.','3','.','.','1'},{'7','.','.','.','2','.','.','.','6'},{'.','6','.','.','.','.','2','8','.'},{'.','.','.','4','1','9','.','.','5'},{'.','.','.','.','8','.','.','7','9'}}System.out.println(isValidSudoku(board))END
  • start / end
  • statement
  • condition
  • loop
  • returns
  • definition
1/24

StartSTART

Interactive control-flow diagram and step-by-step code walkthrough.

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits