[Amazon] FULLTIME ONLINE ASSESSMENT 2025 Start – 22 Dec

Problem: Make Array Zero by Subtracting Equal Amounts (LC 2375)

You are given a non-negative integer array nums. In one operation, you must:

  • Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.
  • Subtract x from every positive element in nums.

Return the minimum number of operations required to make every element in nums equal to 0.


Examples

Example 1:

Input:
nums = [1, 5, 0, 3, 5]

Output:
3

Explanation:

  1. In the first operation, choose x = 1.
    Now, nums becomes [0, 4, 0, 2, 4].
  2. In the second operation, choose x = 2.
    Now, nums becomes [0, 2, 0, 0, 2].
  3. In the third operation, choose x = 2.
    Now, nums becomes [0, 0, 0, 0, 0].

Example 2:

Input:
nums = [0]

Output:
0

Explanation:
Each element in nums is already 0, so no operations are needed.


Constraints:

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 100

Problem: Minimum Swaps to Make Palindrome

You are given a binary string s, consisting of characters '0' and '1'. Transform this string into a palindrome by performing some operations. In one operation, you can swap any two characters s[i] and s[j]. Determine the minimum number of swaps required to make the string a palindrome. If it is impossible to do so, return -1.


Note:

A palindrome is a string that reads the same backward as forward. Examples of palindromes: "0", "111", "010", "10101".
Examples of non-palindromes: "001", "10", "11101".


Examples

Example 1:

Input:
s = "0100101"

Output:
1

Explanation:
The following steps show the minimum number of operations required (using 1-based indexing):

  1. Swap characters at indices (4, 5).

Resulting string: "0101010", which is a palindrome.


Constraints:

  • 1 <= s.length <= 10^5
  • s[i] is either '0' or '1'.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *