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. Cut the sticks
  5. Discussions

Cut the sticks

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

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

  • foxeed
    2 months ago+ 1 comment

    There's no need to actually do the "cut" part, and it can be done in just two passes. The insight here is that number of sticks after all the chops in one round is a number of sticks with the higher length.

    sticks-length sticks-cut
    5 4 4 2 2 8      6
    3 2 2 _ _ 6      4
    1 _ _ _ _ 4      2
    _ _ _ _ _ 3      1
    _ _ _ _ _ _    DONE
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy