Skip to content

Feat/cuddly kittens python solution -> main#19

Open
alangnt wants to merge 2 commits intocodedex-io:mainfrom
alangnt:feat/cuddly-kittens-python-solution
Open

Feat/cuddly kittens python solution -> main#19
alangnt wants to merge 2 commits intocodedex-io:mainfrom
alangnt:feat/cuddly-kittens-python-solution

Conversation

@alangnt
Copy link
Copy Markdown
Contributor

@alangnt alangnt commented Mar 23, 2026

Hi Codédex team,

This PR adds a working Python solution for today's Cuddly Kittens 🐈 challenge, and updates the README.md file with today's link.

Here's the code :

def cuddly_kittens(kittens, limit):
  # init a variable longest
  longest = 0
  
  # for each cat
  for i in range(len(kittens)):
    # for each cat on the right
    for j in range(i, len(kittens)):
      # we define a group of
      # current kitten + the one on the right
      group = kittens[i:j+1]

      # we check if group is calm
      if max(group) - min(group) <= limit:
        longest = max(longest, j - i + 1)
      else:
        break
  
  return longest

Here's how it works :

  • starts with longest = 0 to track the best result found
  • for each cat create a group of the current cat + the one on its right
  • it then calculates if the group is calm
  • if yes, updates the longest with the new group
  • if no, ends the loop
  • finally returns the longest group of calm kittens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant