PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Find kth smallest in sorted 2D matrix

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving and data-structure reasoning, focusing on order statistics and operations on a row- and column-sorted matrix within the Coding & Algorithms domain.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Find kth smallest in sorted 2D matrix

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an `n x m` matrix of integers where **each row and each column is sorted in non-decreasing order**. You are also given an integer `k` such that `1 <= k <= n * m`. Return the **k-th smallest element** in the matrix, where elements are ordered by value in non-decreasing order and duplicates are counted according to their occurrences. **Example:** - Input: - `matrix = [[1, 5, 9], [10, 11, 13], [12, 13, 15]]` - `k = 8` - All elements in sorted order: `[1, 5, 9, 10, 11, 12, 13, 13, 15]` - Output: `13` (the 8th element in the sorted list). Design an algorithm that is more efficient than flattening the matrix and fully sorting all `n * m` elements.

Quick Answer: This question evaluates algorithmic problem-solving and data-structure reasoning, focusing on order statistics and operations on a row- and column-sorted matrix within the Coding & Algorithms domain.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Dec 8, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

You are given an n x m matrix of integers where each row and each column is sorted in non-decreasing order.

You are also given an integer k such that 1 <= k <= n * m.

Return the k-th smallest element in the matrix, where elements are ordered by value in non-decreasing order and duplicates are counted according to their occurrences.

Example:

  • Input:
    • matrix = [[1, 5, 9], [10, 11, 13], [12, 13, 15]]
    • k = 8
  • All elements in sorted order: [1, 5, 9, 10, 11, 12, 13, 13, 15]
  • Output: 13 (the 8th element in the sorted list).

Design an algorithm that is more efficient than flattening the matrix and fully sorting all n * m elements.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Software Engineer•TikTok Software Engineer•TikTok Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ 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.