1122. Relative Sort Array | LeetCode Solution

In this video, I solve LeetCode Problem 1122 — Relative Sort Array using an easy and beginner-friendly approach in C++. 📌 Problem Statement: Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also present in arr1. Sort the elements of arr1 such that: The relative ordering of elements that appear in arr2 matches the order in arr2. Elements not present in arr2 are placed at the end in ascending order. 🔹 Example 1: Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19] arr2 = [2,1,4,3,9,6] Output: [2,2,2,1,4,3,3,9,6,7,19] Explanation: Elements present in arr2 are arranged according to its order, while the remaining elements are sorted and placed at the end. 🔹 Example 2: Input: arr1 = [28,6,22,8,44,17] arr2 = [22,28,8,6] Output: [22,28,8,6,17,44] Explanation: The elements from arr2 appear first in the required order, followed by the remaining elements in ascending order. 💡 In this solution, we will: Use Frequency Counting (Hash Map) Preserve the order defined by arr2 Sort the remaining elements separately Achieve an efficient solution Write clean and optimized C++ code 🚀 Perfect for beginners practicing: Arrays, Hashing, Counting Sort, Sorting, LeetCode Easy Problems, C++ DSA Preparation If you found this video helpful, make sure to Like 👍, Share 📤, and Subscribe 🔔 for more coding and DSA content! Problem-Specific Tags

LeetCode was HARD until I Learned these 15 Patterns
▶︎

LeetCode was HARD until I Learned these 15 Patterns

LeetCode Was Hard Until I Learned THESE 8 Patterns (With Templates!)
▶︎

LeetCode Was Hard Until I Learned THESE 8 Patterns (With Templates!)

How I Approach a New Leetcode Problem (live problem solving)
▶︎

How I Approach a New Leetcode Problem (live problem solving)

🔴 Makkah Live | مكة مباشر | الحرم المكي مباشر | قناة القران الكريم السعودية مباشر | مكه المكرمه
▶︎

🔴 Makkah Live | مكة مباشر | الحرم المكي مباشر | قناة القران الكريم السعودية مباشر | مكه المكرمه

LeetCode 27: Remove Element Explained
▶︎

LeetCode 27: Remove Element Explained

All Of Roblox Lua (Luau) in 21 Minutes
▶︎

All Of Roblox Lua (Luau) in 21 Minutes

Abstract Black and White wave pattern| Height Map Footage| 3 hours Topographic 4k  Background
▶︎

Abstract Black and White wave pattern| Height Map Footage| 3 hours Topographic 4k Background

God Says:"TAKE THIS MESSAGE SERIOUSLY, BECAUSE ONLY YOU ARE SEEING IT"/God Message Now/God Message
▶︎

God Says:"TAKE THIS MESSAGE SERIOUSLY, BECAUSE ONLY YOU ARE SEEING IT"/God Message Now/God Message

Relaxing Rain Sounds and Soft Piano Music for Deep Sleep, Stress Relief, and Peaceful Nights
▶︎

Relaxing Rain Sounds and Soft Piano Music for Deep Sleep, Stress Relief, and Peaceful Nights

Elon rages in SpaceX bubble crash
▶︎

Elon rages in SpaceX bubble crash

TV ART SLIDESHOW | Abstract Art for your TV | Jené Stephaniuk | 1hour of 4K HD Paintings
▶︎

TV ART SLIDESHOW | Abstract Art for your TV | Jené Stephaniuk | 1hour of 4K HD Paintings

Moody Gardens Penguin Cam LIVE | Penguin Habitat Stream at the Aquarium in Galveston, Texas
▶︎

Moody Gardens Penguin Cam LIVE | Penguin Habitat Stream at the Aquarium in Galveston, Texas

The FULL VIDEO of Trump they didn’t want released
▶︎

The FULL VIDEO of Trump they didn’t want released

Data Structure and Algorithm Patterns for LeetCode Interviews – Tutorial
▶︎

Data Structure and Algorithm Patterns for LeetCode Interviews – Tutorial

🔴 Makkah Live | مكة مباشر | الحرم المكي مباشر | قناة القران الكريم السعودية مباشر | مكه المكرمه
▶︎

🔴 Makkah Live | مكة مباشر | الحرم المكي مباشر | قناة القران الكريم السعودية مباشر | مكه المكرمه

The 5-Step DP Formula That Solves Any Problem !
▶︎

The 5-Step DP Formula That Solves Any Problem !

Unbelievable Smart Worker & Hilarious Fails | Construction Compilation #7 #adamrose #smartworkers
▶︎

Unbelievable Smart Worker & Hilarious Fails | Construction Compilation #7 #adamrose #smartworkers

NERVOUS 12-Year-Old Who Can Sing Without Opening Her Mouth Earns Mel B's GOLDEN BUZZER!
▶︎

NERVOUS 12-Year-Old Who Can Sing Without Opening Her Mouth Earns Mel B's GOLDEN BUZZER!

Hans Zimmer - Interstellar (Space Sounds)
▶︎

Hans Zimmer - Interstellar (Space Sounds)

How I would learn Leetcode if I could start over
▶︎

How I would learn Leetcode if I could start over