Draft
Digits Frequency In a Given Range
6 of 24nachoMonllor
Description:
Given an array of large numbers represented as BigInteger[] arr
and a set of queries (int[,] queries
), your task is to determine the frequency of a specific digit within a given range of the array.
Each query has the form [L, R, X]
, where:
L
is the start index (inclusive) of the subarray.R
is the end index (inclusive) of the subarray.X
is the target digit whose frequency you need to count.
Input:
- An array of
BigInteger[] arr
, where each element is a large number. - A matrix
queries
, where each row is a query in the format[L, R, X]
.
Output:
Return an array of integers where each element corresponds to the frequency of the digit X
in the subarray arr[L..R]
.
Examples:
BigInteger[] arr = { new BigInteger(222), new BigInteger(54888), new BigInteger(321),
new BigInteger(1000), new BigInteger(5840000003), new BigInteger(334491) };
int[,] queries = { {0, 1, 2}, {1, 4, 8}, {4, 5, 7} };
FrequencyDigits(arr, queries)
// Output: {3, 4, 0}
Explanation:
Query [0, 1, 2]:
- Subarray:
{ 222, 54888 }
- Target digit:
2
- Result: The digit
2
appears 3 times in the subarray.
- Subarray:
Query [1, 4, 8]:
- Subarray:
{ 54888, 321, 1000, 5840000003 }
- Target digit:
8
- Result: The digit
8
appears 4 times in the subarray.
- Subarray:
Query [4, 5, 7]:
- Subarray:
{ 5840000003, 334491 }
- Target digit:
7
- Result: The digit
7
does not appear in the subarray.
- Subarray:
Note:
- It is important that the solution is efficient, especially for large arrays and a large number of queries.
Arrays
Dynamic Programming
Similar Kata:
Stats:
Created | Jun 30, 2021 |
Warriors Trained | 40 |
Total Skips | 0 |
Total Code Submissions | 128 |
Total Times Completed | 24 |
Java Completions | 6 |
Total Stars | 2 |
% of votes with a positive feedback rating | 54% of 14 |
Total "Very Satisfied" Votes | 7 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 6 |
Total Rank Assessments | 15 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |