Grokking Amazon Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content

Solution: Minimum Number of Operations to Make Array Empty
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given an array nums consisting of positive integers.

You can perform below two operations on the array multiple times:

  • Select two elements with equal values and delete them from the array.
  • Select three elements with equal values and delete them from the array.

Return the minimum number of operations required to make the array empty, or -1 if it is not possible.

Examples

Example 1:

  • Input: nums = [1, 3, 2, 1, 2, 2, 3]
  • Expected Output: 3
  • Justification: We can perform the following operations:

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible