Python Array Problem: Missing & Repeating Number

Day 53 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the Missing and Repeating Number in an array. This is a classic mathematical + array problem and frequently asked in coding interviews. What the program does: • Takes an array of size n containing numbers from 1 to n • One number is missing and one is repeating • Uses mathematical formulas to find both efficiently • Returns: Missing number Repeating number Example Input: [3, 1, 2, 5, 3] Output: Missing = 4 Repeating = 3 How the logic works: Use formulas: 👉 Sum of first n numbers S = n(n+1)/2 👉 Sum of squares P = n(n+1)(2n+1)/6 Then: • Find difference of sums • Find difference of squares • Solve equations to get missing & repeating numbers Why this is important: – Combines math + arrays + logic – Optimized solution (no brute force) – Common in interviews (Amazon, Google basics) – Improves analytical thinking Time Complexity: O(n) Space Complexity: O(1) Key learnings from Day 53: – Using mathematical formulas in coding – Avoiding brute-force approaches – Solving equations programmatically – Writing optimized solutions #100DaysOfCode #Day53 #Python #PythonProgramming #Arrays #DSA #Algorithms #ProblemSolving #CodingPractice #InterviewPrep #Optimization #LogicBuilding #DeveloperJourney #Consistency #BTech #CSE #AIandML #VITBhopal #TechJourney

  • text

To view or add a comment, sign in

Explore content categories