algorithm - What is the wrong with my java code, its not clearing all the tests? -
though problem easy. here :
problem statement
password security important topic today. define password system here set of requirements valid password in system must fulfill. in each such system every valid password consists of digits [0−9]. in addition, each such system there 2 requirements valid password must fulfill:
minimum length of valid password.
maximum length of valid password.
we password system secure if , if there more 1 million (106) different possible passwords in system. task, security expert, decide given password system if secure.
note
repetition of digits allowed. 111 valid password of length 3.
leading 0's allowed. 001 , 000 valid password of length 3.
you have consider sum of passwords length lies in range of minimum , maximum value. if minimum length 3 , maximum length 5, have find total count of passwords length either 3, 4 or 5.
input format
in first line there single integer, t, denoting number of test cases.
t lines follow.
the ith line denotes single test case , describes given password system. consists of 2 integers, m , m, denoting minimum password length , maximum password length in system.
constraints
1≤t≤100
1≤m≤m≤10
output format
print t lines. in ith of them print "yes" (without quotes) if ith password system secure, otherwise print "no" (without quotes).
sample input
2 5 5 7 8
sample output
no yes
explanation
sample case #00 valid passwords have length 5, hence there 100000 different passwords; system in insecure, because need more million different passwords system secure. sample case #01 allowed have passwords of length 7 or 8 , since there more million different such passwords, system secure.
my understanding: since repetition allowed have compute 10^m 10^m , sum them through. if m >= 6 dont have compute directly can "yes" , if m <= 5 can "no" directly.
here code :-
import java.io.*; import java.util.*; public class solution { public static void main(string[] args) { /* enter code here. read input stdin. print output stdout. class should named solution. */ scanner scan = new scanner(system.in); int cases = scan.nextint(); int minl = 0, maxl = 0; int sum = 0; for(int = 0; < cases; i++){ minl = 0; maxl = 0; sum = 0; minl = scan.nextint(); maxl = scan.nextint(); if(maxl >= 6){ system.out.println("yes"); }else if(maxl <= 5){ system.out.println("no"); }else if(minl >= 6){ system.out.println("yes"); }else if((maxl - minl) >= 6){ system.out.println("yes"); }else{ for(double k = minl; k <= maxl; k++){ sum += math.pow(10.0 , k); } if(sum >= 1000000){ system.out.println("yes" ); }else{ system.out.println("no"); } } } } }
and code failing clear tests. alas!
the problem statement says print yes "if , if there more than 1 million different possible passwords in system."
it looks code checking more or equal if(maxl >= 6)
.