- 01Getting Started
- 02Your First Output (printf)
- 03Working with Variables
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Function
- 07Working with Arrays
- 08Loops (while statements)
- 09Working with Structs
- 10Error Handling (Checking a Return Value)
- 11Sorting an Array (Bubble Sort)
- 12Recursive Functions
- 13The String-Handling Standard Library
- 14The switch Statement
- 15The Ternary Operator
- 16Pointer Basics
- 17Writing Comments
- 18Logical Operators (&&, ||, !)
- 19Constants (#define and const)
- 20Splitting Strings (strtok)
- 21Handling NULL Pointers Safely
- 22Searching an Array (Looping with strcmp)
- 23Transforming an Array (map-like Logic)
- 24Two-Dimensional Arrays (Tabular Data)
- 25Custom Errors (Categorizing with Error Codes)
- 26Using Variable-Length Argument Lists (stdarg.h)
- 27Removing Duplicates from an Array (Set-Like Logic)
- 28Checking Correctness with the assert Macro (Your First Step into Testing)
- 29Higher-Order Functions (Passing a Function Pointer as an Argument)
- 30Stacks and Queues (Basic Data Structures)
- 31Type Conversion (Casting) Basics
- 32Intro to Regular Expressions (regex.h)
- 33The Binary Search Algorithm
- 34Building a Caesar Cipher (a Character-Shifting Cipher)
- 35Understanding How Selection Sort Works
- 36Building and Displaying Dates (struct tm)
- 37Writing Multiple Test Cases Together
- 38Speeding Up Calculations with Memoization (Caching)
- 39Normalizing Strings (Stripping Whitespace, Unifying Case)
- 40Shallow Copy vs. Deep Copy
- 41Enum (Enumerated Types) Basics
- 42Flattening an Array
- 43Reversing a String and Checking for Palindromes
- 44Pairing Up Two Arrays (the zip operation)
- 45Rounding Numbers (floor, ceil, round)
- 46Multi-Line Strings (Adjacent String Literal Concatenation)
- 47Functions That Return Multiple Values (Structs)
- 48Finding the GCD and LCM (the Euclidean Algorithm)
- 49Formatting Numbers (Padding Digits, Decimal Places)
- 50Bundling Cleanup Logic with goto
- 51Writing Type-Agnostic Logic with Macros
- 52File Reading and Writing Basics
- 53Generating Random Numbers
- 54Bitwise Operators (AND, OR, XOR, shifts)
- 55Reading Command-Line Arguments
- 56Waiting for a Fixed Amount of Time (sleep)
- 57Watch Out for Floating-Point Rounding Errors
- 58Reading from Standard Input
- 59FizzBuzz (the Classic Practice Problem)
- 60Checking Whether a Number Is Prime
- 61Set Operations with an Array (Intersection, Difference)
- 62Converting Number Bases (Binary, Hex)
- 63Checking Balanced Parentheses (an Application of Stacks)
- 64Checking Whether Two Words Are Anagrams
- 65Checking Whether a Year Is a Leap Year
- 66Converting Temperature (Celsius to Fahrenheit)
- 67Prime Factorization
- 68[Applied] Build a Simple Grade Aggregation Program
Removing Duplicates from an Array (Set-Like Logic)
This lesson covers removing duplicates from an array in C, so you understand the basics of set-like logic. It's for anyone searching "C array deduplication implementation."
C has no dedicated Set type, but you can build duplicate-free data by adding "only values not already present" into a new array. Checking whether a value is already included before adding it is the basic idea.
The example checks whether each element of nums is already present in the unique array using an inner for loop, and adds it if not. This is a simple implementation that uses a nested loop for both searching and adding.
A common early mistake is not accounting for processing speed with a large amount of data. This method's processing time grows proportional to the square of the element count, making it unsuitable for a large dataset โ a faster method would need something like a hash table.
In real projects, understanding the efficiency of simple algorithms like this matters, since C often runs in constrained environments.
๐งช This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
