Tap here to switch tabs
Problem
Submissions

Problem: Distribute Elements Into Two Arrays I

med
30 min
Try to solve the Distribute Elements Into Two Arrays I problem.

Statement

You are given a 11 indexed integer array nums of length n containing distinct elements.

You need to distribute all elements of nums into two arrays, arr1 and arr2, across n operations:

  • In the first operation, append nums[1] to arr1.

  • In the second operation, append nums[2] to arr2.

  • For each subsequent iextthi^{ ext{th}} operation where 3≤i≤3 \leq i \leq n:

    • If the last element of arr1 is greater than the last element of arr2, append nums[i] to arr1.

    • Otherwise, append nums[i] to arr2.

Return the array formed by concatenating arr1 and arr2.

Constraints:

  • 3≤3 \leq n ≤50\leq 50

  • 1≤1 \leq nums[i] ≤100\leq 100

  • All elements in nums are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Distribute Elements Into Two Arrays I

med
30 min
Try to solve the Distribute Elements Into Two Arrays I problem.

Statement

You are given a 11 indexed integer array nums of length n containing distinct elements.

You need to distribute all elements of nums into two arrays, arr1 and arr2, across n operations:

  • In the first operation, append nums[1] to arr1.

  • In the second operation, append nums[2] to arr2.

  • For each subsequent iextthi^{ ext{th}} operation where 3≤i≤3 \leq i \leq n:

    • If the last element of arr1 is greater than the last element of arr2, append nums[i] to arr1.

    • Otherwise, append nums[i] to arr2.

Return the array formed by concatenating arr1 and arr2.

Constraints:

  • 3≤3 \leq n ≤50\leq 50

  • 1≤1 \leq nums[i] ≤100\leq 100

  • All elements in nums are distinct.