Problem · Array

Three Partition Array

EasyMicrosoftPHONE SCREEN
See Microsoft hiring insights

Given an array and a range [lowVal, highVal], partition the array into three parts:

  • All elements smaller than lowVal come first.
  • All elements in the range [lowVal, highVal] come next.
  • All elements greater than highVal come last.
  • Additionally: If lowVal and highVal exist in the array, ensure that lowVal appears before highVal in the final result. The relative order of elements within each group doesn't matter.

    Function Description

    Complete the function threePartitionArray in the editor.

    threePartitionArray has the following parameters:

    1. int arr[]: an array of integers
    2. int lowVal: an integer representing the lower bound of the range
    3. int highVal: an integer representing the upper bound of the range

    halo frenz - you might want to checkout lc75. They said that these 2 questions are relevant :)

    Examples
    01 · Example 1
    arr = [1, 14, 5, 20, 4, 2, 54, 20, 87, 98, 3, 1, 32]
    lowVal = 14
    highVal = 20
    return = [1, 5, 4, 2, 1, 3, 14, 20, 20, 98, 87, 32, 54]
    nothin found 🥹
    Constraints
    nothin found againnnn 😭
    More Microsoft problems
    drafts saved locally
    public int[] threePartitionArray(int[] arr, int lowVal, int highVal) {
      // write your code here
    }
    
    arr[1, 14, 5, 20, 4, 2, 54, 20, 87, 98, 3, 1, 32]
    lowVal14
    highVal20
    expected[1, 5, 4, 2, 1, 3, 14, 20, 20, 98, 87, 32, 54]
    checking account