Draft

Digits Frequency In a Given Range

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.
  • Query [1, 4, 8]:

    • Subarray: { 54888, 321, 1000, 5840000003 }
    • Target digit: 8
    • Result: The digit 8 appears 4 times in the subarray.
  • Query [4, 5, 7]:

    • Subarray: { 5840000003, 334491 }
    • Target digit: 7
    • Result: The digit 7 does not appear in the subarray.

Note:

  • It is important that the solution is efficient, especially for large arrays and a large number of queries.
Arrays
Dynamic Programming

Stats:

CreatedJun 30, 2021
Warriors Trained40
Total Skips0
Total Code Submissions128
Total Times Completed24
Java Completions6
Total Stars2
% of votes with a positive feedback rating54% of 14
Total "Very Satisfied" Votes7
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes6
Total Rank Assessments15
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • nachoMonllor Avatar
Ad