Huawei's OD2023 (Paper B) test question bank is fully covered. Click here for the question writing guide.
Share candies
Knowledge point greedy
Time limit: 1s Space limit: 32MB Limited language: No limit
Topic description:
Xiao Ming randomly grabbed a handful of candies from the candy box, and each time Xiao Ming would take out half of the candies and give them to his classmates.
When the candies cannot be distributed equally, Xiao Ming can choose to take out a candy from the candy box (assuming there are enough candies in the box) or put back a candy.
How many times does Xiao Ming need at least (one count of taking out, putting back, and even distribution) to distribute the candies in his hand until only one is left.