Arrays & Hashing pattern

Distribute Candies

Alice has n candies of various types and her doctor tells her to eat only n/2 of them. Return the maximum number of different types she can keep while eating exactly n/2 candies. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 575
  • Easy
  • 2 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

Arrays & HashingLeetCode 575

Easy

From the first idea to the best one

  1. 01 Brute force · simulate the picking O(n)O(n) space
  2. 02 Optimized · min of two limits O(n)O(n) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Distribute Candies and spot the arrays & hashing pattern in it
  • Brute force · simulate the picking: O(n) time, O(n) space
  • Optimized · min of two limits: O(n) time, O(n) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Arrays & Hashing

See Distribute Candies run, step by step

Sign in and this page opens on the animation, with all 13 Arrays & Hashing problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.