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 | 力扣

  • 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 | 力扣

  • Tags: Array, Divide And Conquer, Greedy, Sorting, Quickselect

667. Beautiful Arrangement II

2122. Recover the Original Array

  • LeetCode | 力扣

  • Tags: Array, Hash Table, Two Pointers, Sorting, Enumeration

932. Beautiful Array

3311. Construct 2D Grid Matching Graph Layout

2573. Find the String with LCP

  • LeetCode | 力扣

  • Tags: Array, String, Dynamic Programming, Greedy, Union Find, Matrix

1982. Find Array Given Subset Sums

280. Wiggle Sort 👑

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]
#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