Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Counting Elements (easy)
On this page

Problem Statement

Try it yourself

Problem Statement

Given a list of integers, determine the count of numbers for which there exists another number in the list that is greater by exactly one unit.

In other words, for each number x in the list, if x + 1 also exists in the list, then x is considered for the count.

Examples:

  1. Example 1:

    • Input: [4, 3, 1, 5, 6]
    • Expected Output: 3
    • Justification: The numbers 4, 3, and 5 have 5, 4, and 6 respectively in the list, which are greater by exactly one unit.
  2. Example 2:

    • Input: [7, 8, 9, 10]
    • Expected Output: 3
    • Justification: The numbers 7, 8, and 9 have 8, 9, and 10 respectively in the list, which are greater by exactly one unit.
  3. Example 3:

    • Input: [11, 13, 15, 16]
    • Expected Output: 1
    • Justification: Only the number 15 has 16 in the list, which is greater by exactly one unit.

Constraints:

  • 1 <= arr.length <= 1000
  • 0 <= arr[i] <= 1000

Try it yourself

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Try it yourself