K-th Lowest Memory Address Problem

K-th Lowest Memory Address Problem — ExecCode Hard DSA Practice

Solve the K-th Lowest Memory Address problem on ExecCode. Free online hard DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.

Problem description

A memory index is stored as a binary search tree of integer address offsets. The tree is encoded by root, a level-order array in which null represents a missing child. The first item is the root. The remaining items give the left and right children of each non-null node in level order. For example, [3, 1, 4, null, 2] describes a BST whose sorted addresses are [1, 2, 3, 4]. Return the k-th smallest address using 1-based indexing. Return -1 if the tree contains fewer than k nodes. You are given: root — the nullable level-order encoding of the BST k — the 1-based rank to retrieve The input is guaranteed to satisfy the binary search tree property. In Python, JSON null appears as None; Java uses nullable Integer values; C++ uses optional .

Examples

Input {'root': [5, 3, 8, 2, 4, 7, 9], 'k': 4}; Output 5. Input {'root': [0, -3, 5, -10, -1, 2, 9], 'k': 1}; Output -10. Input {'root': [5, 4, None, 3, None, 2, None, 1], 'k': 3}; Output 3

Constraints

0 <= root.length <= 100000\n- Every non-null value is a unique 32-bit integer\n- The encoded tree satisfies the binary search tree property\n- 1 <= k <= 100001

Practice K-th Lowest Memory Address free on ExecCode. Browse DSA problems, topic map, and placement guides.