Computer Science, asked by REDBALLZ4532, 10 hours ago

Raj is given an integer N in the form of a string. Raj needs to give this string to his mother on her birthday as a gift. But before that he will have to remove at most 1 digit from the number such that the rest of the digits. remain at their respective relative position. He wishes to make the value of nk maximum possible where k is an integer which he already has. Help him prepare a gift for his mother.

Answers

Answered by shantanuchoudhary310
0

Answer:

cjjcjfjgigogogofidufufududjchxnxjdufufidudidh

Explanation:

fifidudidudududdufufufufufifududufudududuufudufi

Answered by ravilaccs
0

Answer:

  • For every picked element, count its occurrences by traversing the array, if count becomes more than n/k, then print the element.

Explanation:

  • Given an array of size n, find all elements in array that appear more than n/k times. For example, if the input arrays is {3, 1, 2, 2, 1, 2, 3, 3} and k is 4, then the output should be [2, 3]. Note that size of array is 8 (or n = 8), so we need to find all elements that appear more than 2 (or 8/4) times. There are two elements that appear more than two times, 2 and 3.
  • A simple method is to pick all elements one by one. For every picked element, count its occurrences by traversing the array, if count becomes more than n/k, then print the element. Time Complexity of this method would be O(n2.
  • // C++ code to find elements whose
  • // frequency yis more than n/k

#include<bits/stdc++.h>

using namespace std;

void morethanNbyK(int arr[], int n, int k)

{

int x = n / k;

// unordered_map initialization

unordered_map<int, int> freq;

for(int i = 0; i < n; i++)

{

 freq[arr[i]]++;

}

// Traversing the map

for(auto i : freq)

{

 // Checking if value of a key-value pair

 // is greater than x (where x=n/k)

 if (i.second > x)

 {

  // Print the key of whose value

  // is greater than x

  cout << i.first << endl;

 }

}

}

// Driver Code

int main()

{

int arr[] = { 1, 1, 2, 2, 3, 5,4, 2, 2, 3, 1, 1, 1 };

int n = sizeof(arr) / sizeof(arr[0]);

int k = 4;

morethanNbyK(arr, n, k);

return 0;

}

Learn more the program

  • https://brainly.in/question/21779531
  • https://brainly.in/question/47543171
Similar questions