↓Skip to main content
  1. LeetCode/

LeetCode 4097: Minimum Value of Merged Integers

·1 min· ·
LeetCode Easy Array String Simulation
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2026-11-02

  • Submissions: Wrong Answer → Accepted

Approach
#

The pairing is fixed by the problem: nums[0] with nums[1], nums[2] with nums[3], and so on. Concatenate each pair’s decimal digits and take the minimum. Just do that: step i by 2 and compare int(str(nums[i]) + str(nums[i + 1])).

Without strings: if b has d digits, the merge is a * 10^d + b.

My Attempts
#

  1. Stepped i by 1 and merged every adjacent pair, adding pairs the problem does not have: [70,41,91,11] returned 4191 (41 merged with 91), the answer is 7041.
  2. Stepping by 2 passed.

Solution
#

class Solution:
    def minMergedInteger(self, nums: List[int]) -> int:
        return min(int(str(nums[i]) + str(nums[i + 1])) for i in range(0, len(nums), 2))

Complexity
#

Time O(n) (each number has at most 4 digits), space O(1).

Mistakes to Avoid
#

  • Read carefully: the pairs are the fixed (0,1), (2,3), …, not every two neighbours.

Interview Explanation
#

The pairs are fixed, so I walk the array with step 2, merge each pair into one integer, and take the minimum. Time O(n).

Related

LeetCode 3838: Weighted Word Mapping
·1 min
LeetCode Easy Array String Simulation
LeetCode 3838 note: sum each word’s letter weights mod 26 and map backward: 0 -> z, i.e. chr(ord(‘z’) - r)
LeetCode 3842: Toggle Light Bulbs
·1 min
LeetCode Easy Hash-Table Simulation Array
LeetCode 3842 note: toggle membership in a set, or keep bulbs appearing an odd number of times, then sort
LeetCode 1646: Get Maximum in Generated Array
·2 mins
LeetCode Easy Array Simulation
LeetCode 1646 note: generate by the rules, nums[i // 2] at even i and nums[i // 2] + nums[i // 2 + 1] at odd i, handling n = 0 separately
LeetCode 1002: Find Common Characters
·1 min
LeetCode Easy Array Hash-Table String
LeetCode 1002 note: count each word and intersect all Counters (minimum count per character), then expand
LeetCode 929: Unique Email Addresses
·2 mins
LeetCode Easy Array Hash-Table String
LeetCode 929 note: split at @, normalize only the local part (drop everything after +, remove dots), rejoin with the domain and collect in a set
LeetCode 944: Delete Columns to Make Sorted
·1 min
LeetCode Easy Array String Longest-Increasing-Subsequence
LeetCode 944 note: take each column with zip(*strs) and count the columns that are not non-decreasing