You are tasked with constructing an array nums of length n such that: all elements are positive integers, the difference between adjacent elements is at most 1, the sum of elements does not exceed maxSum, and the value at index index is maximized. Return the value at index in the array nums.
You are given an even integer n and a permutation perm of size n where initially perm[i] = i (0-indexed). In each operation, you create a new array arr based on certain rules and update perm to arr. The goal is to determine the minimum number of operations required to restore perm to its initial state.
You are given a string s containing several bracket pairs with non-empty keys. You are also provided a 2D array knowledge where each element is a key-value pair. Your task is to evaluate the string by replacing the keys inside the bracket pairs with their corresponding values. If a key is unknown, replace it with a question mark ?.
You are given two sentences, sentence1 and sentence2, which consist of words separated by spaces. Two sentences are considered similar if you can insert any number of words (including none) into one of the sentences to make them identical. The inserted words must be separated by spaces.
You are given an array of non-negative integers. A pair of indices (i, j) is nice if nums[i] + rev(nums[j]) equals nums[j] + rev(nums[i]). Return the number of nice pairs modulo 10^9 + 7.