We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Modified Kaprekar Numbers
Modified Kaprekar Numbers
Sort by
recency
|
1025 Discussions
|
Please Login in order to post a comment
Hi there! Here's my Java solution:
https://github.com/eduardocintra/hacker-rank-solutions/blob/master/src/br/com/eduardocintra/easy/modifiedkaprekarnumbers/ModifiedKaprekarNumbers.java
Here is my c++ solution, you can what the explanation here : https://youtu.be/MttrQCHGu3w
C++ O((q−p+1) log(q)) solution:
My solution in java whitout using any String or StringBuilder method. Passes all test cases.
Python
def kaprekarNumbers(p, q): kap=[] for i in range(p,q+1): sqr=str(i*i) r=sqr[len(sqr)-len(str(i))::] l=round(int(sqr)/(10**len(r)),0) if l+int(r)==i: kap.append(i) if len(kap)!=0: print(*kap, sep=" ") else: print("INVALID RANGE")