Ticket Pricing System - Problem

You are building a movie ticket pricing system that calculates the correct ticket price based on age and day of the week.

Pricing Rules:

  • Child (age < 12): $5
  • Adult (age 12-59): $10
  • Senior (age 60+): $7

Weekend Surcharge: Add $3 to the base price if isWeekend is true.

Given a person's age and whether it's a weekend, return the total ticket price.

Input & Output

Example 1 — Child Weekend
$ Input: age = 8, isWeekend = true
Output: 8
💡 Note: Age 8 is a child (< 12), so base price is $5. Weekend adds $3 surcharge. Total: $5 + $3 = $8
Example 2 — Adult Weekday
$ Input: age = 25, isWeekend = false
Output: 10
💡 Note: Age 25 is adult (12-59), so base price is $10. No weekend surcharge. Total: $10
Example 3 — Senior Weekend
$ Input: age = 65, isWeekend = true
Output: 10
💡 Note: Age 65 is senior (60+), so base price is $7. Weekend adds $3 surcharge. Total: $7 + $3 = $10

Constraints

  • 0 ≤ age ≤ 150
  • isWeekend is either true or false

Visualization

Tap to expand
INPUTALGORITHMRESULTAge8WeekendtrueCustomer: 8-year-oldvisiting on Saturday1Check Age CategoryAge 8 < 12 → Child2Apply Base PriceChild rate = $53Weekend SurchargeWeekend = true → +$34Calculate Total$5 + $3 = $8Final Ticket Price$8Child weekend ticketBase $5 + Weekend $3Key Insight:Age-based conditional logic with inline weekend surcharge calculationprovides clean, efficient ticket pricing in O(1) time.TutorialsPoint - Ticket Pricing System | Single If-Else Chain
Asked in
Amazon 25 Microsoft 18 Google 15
23.5K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen