PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving skills focused on array processing, intersection across multiple sorted sequences, and time/space complexity analysis.

  • easy
  • SoFi
  • Coding & Algorithms
  • Software Engineer

Find Smallest Common Row Value

Company: SoFi

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given a 2D integer matrix where each row is sorted in strictly increasing order. Return the smallest integer that appears in every row. If no such integer exists, return -1. Assumptions: - The matrix contains at least 1 row and 1 column. - All rows have the same length. - Values can be negative or positive. Example: Input: [ [1, 2, 3, 4, 5], [2, 4, 5, 8, 10], [3, 5, 7, 9, 11], [1, 3, 5, 7, 9] ] Output: 5 During the interview, you may also be asked to clarify edge cases and write test methods or unit test cases for your solution.

Quick Answer: This question evaluates algorithmic problem-solving skills focused on array processing, intersection across multiple sorted sequences, and time/space complexity analysis.

You are given a 2D integer matrix where each row is sorted in strictly increasing order. Return the smallest integer that appears in every row. If no such integer exists, return -1. Because each row is sorted, you should aim for a solution that uses that structure instead of comparing every value against every other value blindly.

Constraints

  • 1 <= number of rows <= 1000
  • 1 <= number of columns <= 1000
  • All rows have the same length
  • Each row is sorted in strictly increasing order
  • -10^9 <= matrix[i][j] <= 10^9

Examples

Input: ([[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]],)

Expected Output: 5

Explanation: The value 5 appears in every row, and no smaller value does.

Input: ([[-4,-1,0,9]],)

Expected Output: -4

Explanation: With only one row, every value in that row appears in every row. The smallest is -4.

Input: ([[1,2,3],[2,4,6],[4,5,7]],)

Expected Output: -1

Explanation: There is no integer that appears in all three rows.

Input: ([[-3,-1,2,4],[-5,-3,2,8],[-10,-3,0,2]],)

Expected Output: -3

Explanation: Both -3 and 2 appear in every row, so the smallest common value is -3.

Input: ([[7],[7],[7]],)

Expected Output: 7

Explanation: Each row contains only 7, so 7 is the smallest common value.

Input: ([[1,5,10,20],[2,5,12,20],[0,5,15,20]],)

Expected Output: 5

Explanation: Both 5 and 20 are common to all rows, and the smallest of them is 5.

Hints

  1. Any valid answer must come from the first row, so you can test its values from left to right.
  2. Since every row is sorted, use binary search to check whether a candidate appears in the other rows.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Format words into wrapped/justified lines - SoFi (medium)
  • Find the second most frequent tag - SoFi (medium)
  • Implement a multithreaded task executor with semaphores - SoFi (medium)
  • Implement chance of a personal best - SoFi (hard)
  • Solve Time-Window and Binary Swap Problems - SoFi (easy)