FastPrepUnique Rows of a Binary Matrix
Problems/Unique Rows of a Binary Matrix

Unique Rows of a Binary Matrix

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One post, published in September 2018 about a campus visit for interns, ends with a list of extra questions that the writer or friends were asked. This task is on it as a link, and the post does not say who got it or in which round.

The link's address is all the post gives. We did not read the page behind it for this problem, and no input form, examples, limits or output order are stated. Here, you get a matrix of 0s and 1s with up to 300 rows and 40 columns and return each different row once, in the order it first appears. Only the answers are checked, so comparing every row with the rows already kept also passes at these sizes.

Our version is about 80% the same as the reported question.

You are given a matrix matrix that holds only 0 and 1. Two rows are the same when they have the same value in every column.

Return the different rows of the matrix, each one exactly once. Keep the rows in the order in which they first appear in matrix: when a row repeats, keep its first copy and drop the later ones.

Return the kept rows as a matrix. The rows are not sorted.

Function

uniqueRows(matrix: int[][]) → int[][]

Examples

Example 1

matrix = [[0,1,1,0],[1,0,0,1],[0,1,1,0],[1,1,1,1],[1,0,0,1]]return = [[0,1,1,0],[1,0,0,1],[1,1,1,1]]
matrix
01230011011001201103111141001
→
return
0123001101100121111

Row 0 is [0, 1, 1, 0] and is new. Row 1 is [1, 0, 0, 1] and is new. Row 2 repeats row 0, so it is skipped. Row 3 is [1, 1, 1, 1] and is new. Row 4 repeats row 1, so it is skipped. The kept rows, in the order they first appear, are [[0, 1, 1, 0], [1, 0, 0, 1], [1, 1, 1, 1]].

Example 2

matrix = [[1,1],[0,1],[1,0],[0,0]]return = [[1,1],[0,1],[1,0],[0,0]]
matrix
01011101210300
→
return
01011101210300

All four rows are different, so every row is kept. The rows stay in the order they were given; they are not sorted.

Example 3

matrix = [[1],[1],[0],[1],[0]]return = [[1],[0]]
matrix
00111203140
→
return
00110

Every row has one column. The first row [1] is kept, the second repeats it, the third [0] is new and kept, and the last two repeat rows that were already seen. The answer is [[1], [0]].

Constraints

  • 1 <= matrix.length <= 300
  • 1 <= matrix[i].length <= 40
  • matrix[i][j] is 0 or 1.
  • All rows have the same length.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Validate Rectangular Game PiecesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Set Matrix ZeroesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions
  • Validate a Sudoku BoardZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
  • Unique Pairs in a 2D Matrix Summing to TargetAmazon · PHONE SCREEN
  • Sparse Matrix MultiplicationByteDance · PHONE SCREENByteDance interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Valid SudokuVerkada · PHONE SCREENVerkada interview questions

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int[][] uniqueRows(int[][] matrix) {
        // Write your code here.
    }
}
Checking account…