0% found this document useful (0 votes)
4K views11 pages

Imocha - Question2

The document provides a coding question to remove the minimum number of elements from an array such that the frequency of each element is divisible by a given integer K. It includes sample input of an array with size 5 and K=2, and the expected output of 1. It also provides an explanation that removing 1 from the array results in frequencies of each element being divisible by 2. The document then lists the basic steps to solve this problem in pseudocode, including getting input, storing the array, initializing variables, using a map to count frequencies, and returning the minimum removals needed.

Uploaded by

Anshu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views11 pages

Imocha - Question2

The document provides a coding question to remove the minimum number of elements from an array such that the frequency of each element is divisible by a given integer K. It includes sample input of an array with size 5 and K=2, and the expected output of 1. It also provides an explanation that removing 1 from the array results in frequencies of each element being divisible by 2. The document then lists the basic steps to solve this problem in pseudocode, including getting input, storing the array, initializing variables, using a map to count frequencies, and returning the minimum removals needed.

Uploaded by

Anshu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Coding Question

November2022-Easy-Q2-FrequencyArray <specimen name> <Anshu Singh>


1. Topic Array Operations

2. Difficulty Level: Easy

3. Question / Problem Statement


Given an array of integers Nums and an integer K. The task is to remove the minimum number
of elements such that frequency of each element is divisible by K.

Function Description
In the provided code snippet, implement the provided minNums(...) method using the
variables to print the pattern for each line from 1 to i. You can write your code in the
space below the phrase “WRITE YOUR LOGIC HERE”.

There will be multiple test cases running so the Input and Output should match exactly
as provided.
The base Output variable result is set to a default value of -404 which can be modified.
Additionally, you can add or remove these output variables.

Input Format
First line contains an integer N: the size of the string array.
Second line contains an integer K.
Third line contains N integers separated by space.

Sample Input
5 -- denotes N
2 -- denotes K
1 1 1 2 2 – denotes Nums
Constraints
1<=N<= 100000.
1<=K<= 100000.

Output Format
Output should return minimum number of elements removed.

Sample Output
1
Explanation
Given Nums [ 1,1,1,2,2] and K=2,
Remove 1 from array.
Now Nums [1,1,2,2]
Hence frequency of each element is divisible by 2.

Therefore, the minimum number of elements removed is 1.

8. Solution Steps:
[Basic Steps: Pseudo algorithm and Pseudo flow that will allow us to write code in most of the
Languages.]

1. Get value from console.


2. And store in variable N.
3. Get value from console.
4. Store in variable K.
5. Create an integer array Nums of length N.
6. Get N integer value from console.
7. Store in integer array Nums
8. Create an integer variable Ans  0
9. Create an int type map mp.
10. For i 0 To N-1.
11. mp[Nums[i]] mp[Nums[i]]+1.
12. EndFor.
13. For i =mp.begin() To mp.end()-1
14. Ans ( (i->second)% K)+Ans.
15. EndFor
16. Return Ans.

9. Running Solution in C, C++ or Java


[Running code that will run accurately on our System or Profoundly used IDE.]

#include<bits/stdc++.h>
using namespace std;

int main()
{
int N,K;
cin>>N>>K;
int Nums[N];
for(int i=0;i<N;i++)cin>>Nums[i];
int Ans=0;
map<int,int>mp;
for(int i=0;i<N;i++)
mp[Nums[i]]++;

for(auto it=mp.begin();it!=mp.end();it++)
{
Ans =((it->second)%K)+Ans;
}
cout<<Ans;
return 0;
}

Input:
5
2
11122
Output:
1

10. Test Cases [ Qty: 12 ]


[ Test Cases: Minimum 12 which are composed of Easy, Complex, Negative and Boundary
Value Cases (BVC). We should be able to insert these in Our System. Realistic Values ]
Test Input Outp Score
Case ut
No
1 1 0 0
1
1
2 2 0 0
1
12
3 3 1 1
2
111
4 4 4 1
3
1231
5 6 4 1
2
6 2 10 5 2 2
6 6 2 1
4
888687
7 10 10 1
6
7 20 17 2 20 11 1 1 17 13
8 20 17 1
3
8 13 15 8 9 2 12 19 11 12 7 7 9 4 10 6 12 20 6 17
9 100 100 1
8
56 27 21 51 100 42 8 53 16 46 83 4 96 85 74 53
92 74 42 100 57 38 22 61 99 12 25 43 77 13 60
60 38 15 94 79 89 100 78 4 78 27 21 82 85 54 48
46 14 36 27 57 49 84 17 48 44 78 93 91 94 95 5
93 93 35 12 53 17 57 37 17 71 70 88 4 1 37 38 89
90 18 38 93 32 81 27 78 3 73 33 78 14 70 12 93
63 74 66 16

10 195 195 1
6
94285 39045 52615 78430 26180 9789 29145
58930 79731 8992 92228 16926 80925 42343
42572 48387 22435 36247 78089 6066 95221
24535 45881 87374 59837 21198 20073 70104
16074 59490 59001 67054 21715 56082 62550
37622 3065 94741 83148 65590 83316 74595
50248 57659 5459 21111 36802 46236 82981
88943 16111 1017 47684 47381 29211 39294
97395 49200 4427 64204 87394 19276 23604
97728 82287 98989 25121 88629 48319 58222
45339 40543 15746 49750 24328 16525 65065
54378 69425 96719 10740 63828 68698 3392
82310 90571 8530 40125 28204 24913 75322
10808 15864 68692 76973 92974 32125 93522
3167 35817 59626 88501 5945 16463 61278
83214 93705 44098 75049 61443 23503 50810
57037 31663 43885 85833 11225 4948 29059
35721 63469 30637 27196 11485 53106 71242
18555 95549 70156 75672 26662 39833 27449
34489 38232 56342 74637 30808 34685 20173
8945 63905 96420 57155 74697 68177 54545
48597 81786 93110 13314 42760 74833 81008
76083 32777 96067 5026 37065 92297 40005
78975 76111 80468 96780 40929 9412 20758
85068 68822 6216 66990 69545 91177 56981
26919 6470 17162 59944 88694 91124 40611
78733 49272 11089 73976 30716 46124 28828
85178 6281 8506 1778 13364 11019

11 1000 1000 1
100000
363 161 450 216 577 646 229 245 584 981 760
704 189 117 639 809 806 59 741 814 575 979
689 631 570 295 421 590 126 824 752 182 44 40
734 753 812 538 468 629 960 54 333 569 220
726 767 861 48 859 406 665 619 63 944 399 570
152 566 302 912 450 926 635 486 642 871 260
888 716 873 832 115 623 667 840 450 720 621
914 138 837 426 121 49 791 823 975 224 103
745 542 116 57 732 582 789 104 348 567 775
618 391 958 118 672 129 817 943 688 274 703
389 837 293 471 676 923 430 25 774 953 198
564 343 500 653 839 258 764 737 969 279 970
266 521 704 644 29 497 798 64 462 712 901 926
716 161 214 948 167 332 342 543 834 354 394
28 549 350 676 972 614 400 345 551 314 80 161
873 381 693 27 515 731 57 136 383 454 675 129
620 600 410 136 209 642 409 998 121 909 343
640 888 215 606 798 5 678 1000 211 524 998
307 712 70 700 137 154 387 749 771 560 693
649 917 870 64 383 922 49 863 409 983 864 928
279 903 898 181 250 777 407 135 661 98 177
896 894 523 569 572 596 73 883 19 438 431 548
975 624 977 769 697 241 740 287 604 707 951
866 342 810 485 948 810 441 782 689 370 253
280 912 607 678 268 207 346 229 255 712 89
831 69 718 860 367 336 876 634 869 484 566
525 291 754 592 193 888 432 286 856 312 815
872 181 316 805 862 33 539 293 402 520 534
139 249 333 197 639 600 1 950 442 240 5 64 252
598 146 603 11 364 89 495 740 406 695 600 442
140 721 757 125 63 65 263 319 449 533 59 812
51 727 699 67 824 597 441 315 408 43 214 758
15 89 68 334 216 725 581 730 619 350 98 210
896 71 729 735 403 546 593 377 742 750 935
106 282 760 776 205 568 135 692 333 535 551
227 586 867 469 983 903 567 261 165 631 479
942 832 43 578 826 312 920 76 846 693 698 842
921 194 112 872 902 130 279 589 791 606 877
949 468 499 238 341 898 865 321 76 328 447
732 646 153 424 522 591 372 746 812 2 369 791
615 607 973 472 928 605 770 45 704 692 681
350 672 455 37 628 943 209 648 259 796 220
530 957 761 366 855 906 455 541 275 400 589
896 42 158 694 351 394 509 166 402 449 113
191 294 683 425 448 449 661 833 707 181 411
235 917 651 130 989 414 285 97 575 916 835
243 889 601 935 657 174 300 837 852 273 211 7
422 29 560 90 644 884 982 271 210 848 135 905
797 953 402 608 380 614 255 559 650 346 774
66 435 331 106 820 280 478 420 376 812 551
247 7 328 63 904 999 96 715 824 793 451 156
948 357 295 646 138 5 858 878 409 473 426 843
247 414 970 36 337 64 717 161 336 729 244 887
779 558 725 469 333 484 285 751 755 189 351
131 12 972 228 425 722 312 193 734 425 73 593
972 336 279 37 339 455 501 141 634 543 233
849 28 564 683 650 460 77 916 573 679 442 614
921 141 576 809 906 655 637 576 425 255 21
773 151 865 110 796 579 98 942 177 173 198 37
531 577 869 931 615 898 195 241 560 584 604
173 844 273 407 895 492 866 598 856 307 201
947 827 820 763 730 598 411 963 800 407 983
280 856 624 253 773 681 708 640 328 802 769
206 593 990 130 192 379 50 413 594 286 652 62
341 408 73 549 765 804 629 574 449 605 385
455 238 775 684 528 678 129 282 595 248 883
676 950 856 309 998 289 981 228 716 33 795
260 434 234 982 889 124 759 539 928 715 108
534 804 710 561 776 934 534 295 102 690 161
419 322 510 119 772 616 644 28 989 594 824 58
256 99 724 82 877 331 942 994 403 516 512 640
344 146 906 123 581 501 785 852 386 648 825
622 626 881 47 829 621 526 18 472 707 691 313
692 447 577 437 795 242 472 351 308 308 762
346 158 965 290 207 307 153 190 179 800 715
189 982 402 382 968 842 825 996 333 553 334
86 7 737 129 272 114 613 793 430 345 381 176
251 9 693 623 887 355 805 403 890 721 310 807
91 73 423 188 300 523 973 471 820 241 86 814
676 378 65 626 529 730 8 46 849 903 871 1 721
765 667 817 502 965 428 685 20 190 933 110
772 396 725 218 477 672 710 687 166 784 612
558 836 522 822 163 738 933 484 682 596 822
605 901 781 608 158 121 895 467 562 37 817
286 823 49 913 615 775 634 96 157 142 136 404
107 745 349 89 159 958 981 897 586 731 883
733 428 578 433 775 885 555 634 101 158 727
959 709 756 529 934 782 992 531 300 302

12 500 20 1
120
100000 100000 99999 99999 100000 99999
99999 99999 99999 99999 99999 100000 99999
99999 99999 100000 99999 99999 99999 100000
100000 100000 100000 99999 99999 100000
100000 99999 100000 100000 99999 99999
100000 99999 99999 100000 99999 99999
100000 99999 100000 100000 100000 99999
100000 99999 99999 100000 100000 100000
99999 99999 99999 100000 100000 99999 99999
99999 100000 100000 99999 100000 99999
100000 100000 100000 99999 99999 100000
100000 100000 99999 99999 100000 99999
100000 100000 99999 99999 100000 100000
99999 99999 100000 99999 99999 99999 99999
100000 100000 99999 99999 99999 100000
99999 100000 99999 99999 99999 100000
100000 99999 100000 99999 99999 100000
100000 100000 99999 100000 100000 100000
99999 100000 100000 99999 99999 99999
100000 100000 100000 99999 99999 99999
100000 99999 99999 100000 100000 100000
100000 99999 99999 99999 100000 99999
100000 100000 99999 100000 100000 99999
100000 99999 100000 99999 99999 99999 99999
100000 99999 99999 99999 100000 99999 99999
100000 100000 99999 100000 99999 100000
100000 100000 100000 99999 100000 99999
100000 100000 99999 100000 99999 100000
99999 100000 99999 99999 99999 99999 100000
100000 99999 99999 100000 100000 99999
99999 99999 100000 99999 99999 99999 100000
99999 99999 99999 100000 99999 99999 100000
100000 100000 99999 100000 100000 99999
100000 99999 99999 100000 99999 100000
99999 99999 99999 99999 100000 99999 100000
100000 100000 100000 99999 99999 100000
99999 100000 100000 99999 99999 99999 99999
100000 100000 99999 99999 100000 99999
99999 100000 100000 99999 99999 99999 99999
99999 100000 100000 100000 99999 99999
100000 100000 99999 99999 100000 100000
99999 99999 100000 100000 100000 100000
99999 99999 100000 100000 100000 100000
100000 100000 99999 100000 99999 99999
99999 99999 99999 100000 100000 100000
100000 99999 99999 100000 99999 99999
100000 100000 99999 100000 99999 99999
100000 100000 99999 99999 100000 99999
100000 100000 100000 100000 100000 100000
100000 100000 100000 100000 100000 99999
100000 100000 99999 100000 99999 99999
100000 100000 100000 99999 100000 100000
99999 99999 100000 99999 100000 99999
100000 99999 100000 99999 100000 99999
100000 100000 100000 99999 99999 100000
100000 100000 99999 100000 99999 100000
99999 99999 100000 99999 99999 100000 99999
99999 100000 100000 99999 100000 99999
100000 99999 100000 99999 100000 100000
100000 99999 100000 100000 99999 100000
100000 99999 99999 100000 99999 100000
99999 99999 100000 99999 99999 100000 99999
99999 100000 99999 100000 100000 99999
99999 99999 99999 99999 99999 100000 99999
100000 99999 99999 99999 100000 99999 99999
100000 100000 99999 100000 99999 99999
99999 100000 99999 99999 100000 99999
100000 100000 99999 100000 100000 100000
100000 100000 100000 99999 99999 99999
99999 99999 100000 100000 100000 99999
99999 99999 100000 100000 100000 99999
100000 100000 100000 99999 99999 100000
100000 99999 100000 100000 100000 100000
100000 100000 100000 99999 99999 99999
100000 100000 99999 100000 100000 99999
99999 100000 99999 99999 99999 100000 99999
99999 99999 99999 100000 99999 99999 99999
99999 99999 100000 100000 99999 99999
100000 99999 100000 100000 100000 99999
100000 99999 99999 100000 100000 99999
99999 99999

Format of Coding Question


Nomenclature: Question ID: Jun2019-Easy-Q1-Multiple Graphs <specimen name>
1. Topic and relation of the question to some theory (This is what we will be introducing from
now on.)

2. Difficulty Level : (Easy, Medium, High) as per the depth of Problem statement and solution
difficulty.

3. Question / Problem Statement


[ Here the Question should be a short and sweet story that can sufficiently explain problem to be
solved. This should not be a clumsy story. It should be simply understandable. Candidate
should be able to Identify Topic by reading ]

Note (if any):

4. Function Description:
[ Here we provide the function name in camelCase(...). Here we define what the function will
return or print. ]

5. Input Format:
[ Here the Candidate will be explained what is acceptable in the Input and how one should
accept Input ]

6. Sample Input:
[ Here the Candidate will be provided with a running Sample Input ]

Constraints (if any):

7. Output Format:
[ Here the Candidate will be explained what is need to be as Output and how one should
present Output ]

8. Sample Output:
[ Here the Candidate will be provided with a running Sample Output ]

9. Explanation of Sample Input and Output:


[ Here the Candidate will be guided and explained with how Sample Input and Output has
arrived to what is shown. ]

10. Solution Steps:


[Basic Steps: Pseudo algorithm and Pseudo flow that will allow us to write code in most of the
Languages.]

11. Running Solution in C, C++ or Java


[Running code that will run accurately on our System or Profoundly used IDE.]
12. Test Cases [ Qty: 12 ]
[ Test Cases: Minimum 12 which are composed of Easy, Complex, Negative and Boundary
Value Cases (BVC). We should be able to insert these in Our System. Realistic Values ]

13. Code stubs (if any):


[ Each code stub will have name as per function description ]

Requirements:
1. Come up with Better and easier Question Format. Less Story, hinting to closeness of answer.
Story should be established with least or no mathematics. Story cannot be more than 2
sentences.

2. Coding Question should become a fun element yet should be able to judge deep serious
intent of programming capacity of the Candidate and provide apparatus (How we can better
calculate Candidate's Coding and Programming Skills... Use of Data Structures and ability to
write optimum solution.)

4. Question should be EEOC and any discriminatory policy compliant:


eg.
a. Cricket is not common globally... Questions cannot be related to unfamiliar subject and
topics.
b. Harmful Words: Bomb, Drugs... so on... Are not allowed.
c. Male and female OR Female and Male... Superiority and Inferiority Discrimination not to be a
part of this.

5. Inspiration: Questions can be like:

Easy
Write a code to find Fibonacci series until 5th number. (It should be as simple as these)

Situational Difficult Questions:


Write a Code that can find 5 star rated songs from a set of Playlists which are repeated in each
Playlist.

New and Advanced Difficulty Questions.

Best topics:

1. Algorithms:
https://www.geeksforgeeks.org/fundamentals-of-algorithms/

2. Advanced Data Structures:


https://www.geeksforgeeks.org/data-structures/#AdvancedDataStructure
3. Latest Trends:
a. Find data from Spatial Matrix.
b. Solvable Analytics.
c. Solvable Big Data.
d. Solvable Smart Algos.

4. Data Science:
https://www.testdome.com/tests/data-science-test/65
https://www.geeksforgeeks.org/tag/data-science/

You might also like