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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Modified Kaprekar Numbers
  5. Discussions

Modified Kaprekar Numbers

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

    You are viewing a single comment's thread. Return to all comments →

  • lokzy
    3 months ago+ 0 comments

    Python3 solution

    def kaprekarNumbers(p, q):
            nums = []
            for i in range(p,q+1):
                    d, sq = len(str(i)) ,str(i**2)
                    if i ==1 or(len(str(i*i))> d and i == int(sq[-d:])+int(sq[:-d]) and int(sq[d:])!=0):
                            nums.append(i)
            if len(nums) == 0:
                    print('INVALID RANGE')
            else:               
                    print(*nums, end="")
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy