Please help me with my code, I am getting wrong answer. Please tell me some cases where my code fails and suggest ways to improve it. //My Code include <stdlib.h>include <stdio.h>include <iostream>using namespace std; int min_positive(int *a, int size_a){ int m = 9, index; for(int i = 1; i<size_a; i++){="" if(m="">a[i]){ m = a[i]; index = i; } } return index; } int min_all(int *a, int size_a){ int m = 9, index; for(int i = 0; i<size_a; i++){="" if(m="">a[i]){ m = a[i]; index = i; } } return index; } int main(){
} asked 15 Jul '14, 00:05

http://ideone.com/IJBjZO i am getting wrong answer for this question. i have tested my code over 20 test cases and its giving correct answer. Can anyone check and give some test cases on which my program is giving wrong answer? answered 31 Dec '15, 23:45
1
check this : 2 7 7 7 7 7 7 7 7 3
(01 Jan '16, 01:34)

@archit910 You may like to go through my solution :D answered 01 Jan '16, 13:05

in the function min_positive , in the for loop i think u should initiate i with 0 and not 1 i dont really understand what exactly you are trying to achieve though .Can you explain what you want to get as output ? answered 15 Jul '14, 00:50

I am giving the idea @archit910 , @abhishek010594 .Check whether this is what you are doing? Now firstly zero is not a valid age. So if the digit 0 has zero frequency the minimum age that cannot be expressed is not 0. However if 1 or 2 or any other digit has the frequency 0, the minimum age that cannot be expressed is 1 or 2 or any of those digit. Now if this is the input: 1 0 0 0 0 0 0 0 0 0 then the minimum age that cannot be expressed is 1. Now if the input is: 2 1 1 1 1 1 1 1 1 1 then the minimum age that cannot be expressed is 11. So this is what you should do. Find the minimum frequency. If the minimum frequency is of a digit which is not zero, print that digit, minimum frequency times+1. If there are many digits with the minimum frequency print the minimum most digit. If the digit zero has minimum frequency then print 1 and 0s minimum frequency+1 times. So if the input is: 0 1 1 1 1 1 1 1 1 1 the output is 10 and if the input is : 1 2 2 2 2 2 2 2 2 2 then the output is 100. However if the input is 1 1 2 2 2 2 2 2 2 2 the answer is 11. That is why first check whether the minimum frequency is the frequency of any other digit other than 0. answered 01 Jan '16, 11:42
