Code Logo

Count Sold Tickets

Published at19 Apr 2026
Easy 0 views
Like0

This problem is based on a simple event ticket check. You have a list that shows whether each ticket was sold or not, and you want to know how many tickets are already taken.

In this version, the list uses 1 for a sold ticket and 0 for an unsold one. Your task is to count the number of ones.

For example, if the status list is [1,1,0,1], the answer is 3 because three tickets are marked as sold.

So the task is to scan the list and count how many sold tickets appear.

Example Input & Output

Example 1
Input
status = []
Output
0
Explanation

An empty list means there are no sold tickets to count.

Example 2
Input
status = [1,1,0,1]
Output
3
Explanation

Three of the tickets are marked as sold.

Example 3
Input
status = [0,0,0]
Output
0
Explanation

If no ticket is sold yet, the count stays 0.

Algorithm Flow

Recommendation Algorithm Flow for Count Sold Tickets
Recommendation Algorithm Flow for Count Sold Tickets

Solution Approach

A clean way to solve this is to use a counter that increases when you find a sold ticket.

Start by creating a variable like sold_count and set it to 0.

Then go through the ticket list one value at a time. For each value, check whether it is equal to 1.

The condition is:

status[i] = 1

If that condition is true, increase sold_count by 1.

After the loop finishes, the counter holds the total number of sold tickets, so that is the final answer.

The logic is simple because every ticket is checked in the same way.

Best Answers

Solutions Coming Soon

Verified best solutions for this Challenge are still being analyzed and will be available soon.