PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

These tasks evaluate algorithmic problem-solving, data structure mastery, and implementation skills within the Coding & Algorithms domain, touching on dynamic programming (longest increasing subsequence), order-statistics in sorted arrays, tree pointer manipulation for perfect binary trees, and graph traversal for connected components.

  • easy
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Solve three classic coding problems

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

You are given three independent coding tasks. Implement a function for each. ## 1) Longest Increasing Subsequence (LIS) Given an integer array `nums`, return the length of the longest **strictly increasing** subsequence. - **Input:** `nums` (array of integers) - **Output:** integer length of the LIS - **Constraints (typical):** `1 <= n <= 2e5` (or smaller), values fit in 32-bit signed int ## 2) k-th Largest Element in Two Sorted Arrays Given two arrays `A` and `B`, each sorted in **non-decreasing** order, and an integer `k` (1-indexed), return the **k-th largest** element in the multiset union of `A` and `B`. - **Input:** `A`, `B` (sorted arrays), `k` - **Output:** the k-th largest element - **Notes:** Arrays may have different lengths; duplicates are allowed. - **Constraints (typical):** `0 <= len(A), len(B) <= 2e5`, `1 <= k <= len(A)+len(B)` ## 3) Connect Nodes at the Same Tree Level Given a **perfect** binary tree (all internal nodes have exactly two children and all leaves are at the same depth), populate each node’s `next` pointer so it points to its immediate neighbor to the right on the same level. If there is no neighbor, set `next = null`. - **Input:** root of a perfect binary tree with fields `left`, `right`, `next` - **Output:** the root (after pointers are populated) - **Requirement (typical):** use `O(1)` extra space (excluding recursion stack) ## 4) Number of Islands Given an `m x n` grid of characters containing `'1'` (land) and `'0'` (water), return the number of **connected components** of land. Cells are connected **4-directionally** (up/down/left/right). - **Input:** `grid` (2D array of `'0'`/`'1'`) - **Output:** integer number of islands - **Constraints (typical):** `1 <= m,n <= 200` (or similar)

Quick Answer: These tasks evaluate algorithmic problem-solving, data structure mastery, and implementation skills within the Coding & Algorithms domain, touching on dynamic programming (longest increasing subsequence), order-statistics in sorted arrays, tree pointer manipulation for perfect binary trees, and graph traversal for connected components.

Longest Increasing Subsequence Length

Return the length of the longest strictly increasing subsequence.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

Input: ([10,9,2,5,3,7,101,18],)

Expected Output: 4

Explanation: Classic example.

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

Expected Output: 1

Explanation: Strictly increasing rejects equals.

Input: ([],)

Expected Output: 0

Explanation: Empty array.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.

K-th Largest in Two Sorted Arrays

Given two non-decreasing arrays and 1-indexed k, return the k-th largest value in their multiset union.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

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

Expected Output: 5

Explanation: Second largest.

Input: ([1,2,2], [2,3], 3)

Expected Output: 2

Explanation: Duplicates count.

Input: ([], [5], 1)

Expected Output: 5

Explanation: One empty array.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.

Serialize Next Pointers by Level

For a perfect binary tree represented as level-order values, return each level as [node,next] pairs after connecting next pointers left to right.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

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

Expected Output: [[[1, None]], [[2, 3], [3, None]], [[4, 5], [5, 6], [6, 7], [7, None]]]

Explanation: Three-level perfect tree.

Input: ([1],)

Expected Output: [[[1, None]]]

Explanation: Single node.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.

Number of Islands

Count four-directionally connected land regions in a binary grid.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

Input: ([['1','1','0'], ['0','1','0'], ['1','0','1']],)

Expected Output: 3

Explanation: Three islands.

Input: ([],)

Expected Output: 0

Explanation: Empty grid.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.
Last updated: Jun 27, 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
  • AI Coding 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

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)