less than 1 minute read

Given a list of integers nums, return the number of sublists where the first element and the last element have the same value.

Constraints

  • n ≤ 10,000 where n is length of nums

https://binarysearch.com/problems/Count-of-Sublists-with-Same-First-and-Last-Values

Examples

Example 1

Input

  • nums = [1, 5, 3, 1]

Output

  • answer = 5

Explanation

The sublists with same first and last element are: [1], [5], [3], [1], [1, 5, 3, 1].

Solution

Leave a comment