Question: Problem 2: Write c++ code to solve the following problem: Given an array of n integers, find the first element that occurs k number of

Problem 2: Write c++ code to solve the following problem: Given an array of n integers, find the first element that occurs k number of times. If no element occurs k times, print -1. Use a map to solve the problem Examples: Input: (1, 7, 4, 3, 4, 8, 7) and k = 2 Input: (4,1, 6, 1, 6, 4) and k = 1 Output: 4 Output:-1 Explanation: Both 7 and 4 occur 2 times, but 4 Explanation: No element occurs 1 time is the first that occurs 2 times
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
