Introduction
The key to success in competitive programming is solving up a lot of easy problems and medium problems, and quite a handful of hard problems. First, you should solve a lot of Easy problems to get command over language and its tools. It would improve your implementation skills. So let us discuss an easy problem today from Leetcode. Have a look at the problem statement below.
Also see, Rabin Karp Algorithm
Problem Statement
Given an 0-index array, ‘ARR’, return the smallest index that satisfies the following condition:
‘i’ % 10 = ARR[i], where i is the index of the array.
If no such element exists, then return -1.
Recall that X % Y is the remainder when X is divided by Y.
Input
4 6 2 7 3 |
Output
3 |
Here ARR[2] = 2. Now 2 % 10 = 2 and ARR[2] is also equal to 2. Therefore the answer is 2 here. There is no other smallest index that satisfies the condition mentioned in the problem.