Posts

Showing posts with the label coding contest

AtCoder Beginner Contest 43: Problem A - Children and Candies Solved! (Two Approaches)

Image
 Hey there, problem solvers! Today we're tackling Problem A from AtCoder Beginner Contest 43: Children and Candies. This problem might seem straightforward at first glance, but it offers an opportunity to explore two solutions with different time complexities. Let's dive in! The Problem Statement Mr. Evi at AtCoder Kindergarten is a generous soul. He's lining up N children and giving them candies based on their position. The first child receives 1 candy, the second 2 candies, and so on, until the Nth child receives N candies. Your task is to find the total number of candies Mr. Evi will need. The problem also specifies that N can range from 1 to 100. Solution 1: Brute Force Loop (Linear Time) This is a classic approach for problems where you need to iterate through a sequence and perform a calculation on each element. Here's how it works: Looping Through Children: We'll use a loop that iterates from 1 to N (number of children). Calculating Candies: Inside the lo...