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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Java
  3. BigNumber
  4. Java BigDecimal
  5. Discussions

Java BigDecimal

Problem
Submissions
Leaderboard
Discussions
Editorial

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

  • SeanRMunoz
    7 years ago+ 12 comments

    My Java 8 lambda solution...

        //Write your code here
        Arrays.sort( s, (as,bs) -> {BigDecimal bd = new BigDecimal(bs); 
           return bd.compareTo(new BigDecimal(as));} );
    

    FAILED with...

    Exception in thread "main" java.lang.NullPointerException
      at java.math.BigDecimal.<init>(BigDecimal.java:806)
      at Solution.lambda`$main$`0(Solution.java:17)
    

    BECAUSE the provided code declared the array too large!

        // REPLACE:
        // String []s=new String[n+2];
    
        // WITH:
           String []s=new String[n];
    

    With the above fix, it now passes all TC's.

    18|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature