SALESFORCE Coding Question – Solved

2 Live
In Salesforce's annual hackathon, employees from a team are ranked based on their efficiency scores. These scores are represented as an array. The team lead wants to analyze subgroups of employees to identify groups with specific characteristics. Given: Β· n employees in a team standing in a line, Β· An array efficiency representing each employee's efficiency, and Β· An integer k (1 ≀ k ≀ n), representing the reference employee in the array. Find the number of subarrays of odd lengths with a median equal to efficiency[k]. Note: Β· A subarray is a sequence of consecutive elements of the array. Β· The median of an array of odd length, say n, is the (n + 1)/2th element of the array if sorted in non-decreasing order. For example, the median of [2, 5, 4, 1, 1, 1, 6] of length 7 is 2, since upon sorting, the array becomes [1, 1, 1, 2, 4, 5, 6] and the (7 + 1)/2 = 4th element is 2. Example: efficiency = [5, 3, 1, 4, 7, 7], k = 4 efficiency[4] = 4. There are 4 odd length subarrays with 4 as their median: [4], [1, 4, 7], [5, 3, 1, 4, 7], [3, 1, 4, 7, 7]. Return 4. Function Description: Complete the function getSpecialSubarrays in the editor below. getSpecialSubarrays has the following parameters: int efficiency[n]: efficiencies of people int k: the index of the required median value Returns long: the number of odd-length subarrays where arr[k] is the median Constraints: Β· The value at efficiency[k] occurs only once in the array. Β· 1 ≀ n ≀ 3 * 10^5 Β· 1 ≀ efficiency[i] ≀ 10^9 Β· 1 ≀ k ≀ n Input Format for Custom Testing Sample Case 0 Sample Input 0 STDIN 3 1 2 FUNCTION n = 3 efficiency = [1, 2, 3] 2 1 Sample Output 0 k = 1 1 Explanation: The only subarray of odd length with 1 as its median is [1].

Asked in: SALESFORCE

Image of the Question

Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |