Skip to content

Construction Problems

Table of Contents

942. DI String Match

1968. Array With Elements Not Equal to Average of Neighbors

1253. Reconstruct a 2-Row Binary Matrix

2182. Construct String With Repeat Limit

  • LeetCode | LeetCode CH (Medium)

  • Tags: hash table, string, greedy, heap priority queue, counting

969. Pancake Sorting

1605. Find Valid Matrix Given Row and Column Sums

2375. Construct Smallest Number From DI String

324. Wiggle Sort II

  • LeetCode | LeetCode CH (Medium)

  • Tags: array, divide and conquer, greedy, sorting, quickselect

667. Beautiful Arrangement II

2122. Recover the Original Array

932. Beautiful Array

3311. Construct 2D Grid Matching Graph Layout

2573. Find the String with LCP

  • LeetCode | LeetCode CH (Hard)

  • Tags: array, string, dynamic programming, greedy, union find, matrix

1982. Find Array Given Subset Sums

280. Wiggle Sort

280. Wiggle Sort - Python Solution
from typing import List


def wiggleSort(nums: List[int]) -> None:
    """
    Do not return anything, modify nums in-place instead.
    """
    n = len(nums)
    for i in range(n - 1):
        if i % 2 == 0:
            if nums[i] > nums[i + 1]:
                nums[i], nums[i + 1] = nums[i + 1], nums[i]
        else:
            if nums[i] < nums[i + 1]:
                nums[i], nums[i + 1] = nums[i + 1], nums[i]


num = [3, 5, 2, 1, 6, 4]
wiggleSort(num)
print(num)  # [3, 5, 1, 6, 2, 4]
280. Wiggle Sort - C++ Solution
#include <iostream>
#include <vector>
using namespace std;

void wiggleSort(vector<int>& nums) {
    int n = nums.size();

    for (int i = 0; i < n - 1; i++) {
        if (i % 2 == 0) {
            if (nums[i] > nums[i + 1]) swap(nums[i], nums[i + 1]);
        } else {
            if (nums[i] < nums[i + 1]) swap(nums[i], nums[i + 1]);
        }
    }
}

int main() {
    vector<int> nums = {3, 5, 2, 1, 6, 4};
    wiggleSort(nums);
    // 3 5 1 6 2 4
    for (size_t i = 0; i < nums.size(); i++) {
        cout << nums[i] << " ";
    }
    cout << endl;
    return 0;
}

484. Find Permutation

1980. Find Unique Binary String

Comments