FastPrepValidate a Latin-Square Matrix
Problems/Validate a Latin-Square Matrix

Validate a Latin-Square Matrix

Karat logoKarat● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The matrix-validation task matches the report at about 95%. All three reported examples are retained. Both rows and columns must pass, resolving the source’s “or” wording using its negative example; square nonempty shape and numeric bounds are stated practice assumptions.

Given a nonempty square integer matrix of size N × N, return whether every row and every column contains each integer from 1 through N exactly once.

For this exercise, assume the row and column conditions must both hold. For example, a matrix whose rows are all [1,2,3] is invalid because its columns repeat values.

Values outside [1,N] make the matrix invalid. The matrix need not have any particular diagonal or arrangement beyond the row and column conditions.

Function

validateLatinSquare(matrix: int[][]) → boolean

Examples

Example 1

matrix = [[1,3,2],[2,1,3],[3,2,1]]return = true
matrix
012013212132321

Every row and column contains exactly 1, 2 and 3.

Example 2

matrix = [[1,2,3],[1,2,3],[1,2,3]]return = false
matrix
012012311232123

Each row is valid, but columns repeat one value and omit others.

Example 3

matrix = [[1000,2,0],[-1000,2,3],[1,2,3]]return = false

Several values lie outside 1 through 3, so the matrix is invalid.

Constraints

  • For this exercise, assume 1 <= N <= 30.
  • The input has exactly N rows of exactly N integers.
  • For this exercise, assume each integer lies in [-10^9,10^9].

More Karat interview questions

  • Do Two Nodes Share a Proper Ancestor?PHONE SCREEN · Seen Sep 2021
  • Parent and Child Counts for Every NodePHONE SCREEN · Seen Sep 2021
  • Validate a Nonogram GridPHONE SCREEN · Seen Aug 2020
  • Nodes With Zero or One ParentPHONE SCREEN · Seen May 2020
  • Lowest Common Ancestor in a Rooted TreeONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Unique Pairs in a 2D Matrix Summing to TargetAmazon · PHONE SCREEN
  • Validate Rows and ColumnsWhatNot · PHONE SCREENWhatNot interview questions
  • Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
  • Sparse Plant Infection SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Sparse Matrix Addition and MultiplicationPinterest · PHONE SCREENPinterest interview questions
  • Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Sparse Matrix MultiplicationByteDance · PHONE SCREENByteDance interview questions
  • Valid SudokuVerkada · PHONE SCREENVerkada interview questions
  • Configurable Tic-Tac-Toe GameEliseAI · PHONE SCREEN
  • Validate Completed SudokuApple · PHONE SCREENApple interview questions
All Karat interview questionsSee Karat hiring insights
Saved
class Solution {
    public boolean validateLatinSquare(int[][] matrix) {
        // Write your code here.
        return false;
    }
}
Checking account…