Special Array II | 3 Detailed Approaches | Beginners Alert | Leetcode 3152 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 129th Video of our Playlist "Arrays 1D/2D Search : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good Array problem : Special Array II | 3 Detailed Approaches | Beginners Alert | Leetcode 3152 | codestorywithMIK
This problem is specially detailed for beginners and hence it's a little lengthy. Hope this video helps to build the thought process.
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Special Array II | 3 Detailed Approaches | Beginners Alert | Leetcode 3152 | codestorywithMIK
Company Tags : will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Intervals_Based_Qn/Special Array II.cpp
Leetcode Link : https://leetcode.com/problems/special-array-ii
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
Approach-1 (Using Cumulative Sum)
Idea: Use a prefix cumulative sum to count violating indices where two consecutive elements have the same parity.
Steps:
Create a cumSum array where cumSum[i] stores the total count of violating indices from the start to index i.
For each query, check if there are any violating indices in the range [start+1, end] by calculating the difference: cumSum[end] - cumSum[start].
If the difference is zero, the subarray is special.
Approach-2 (Using Two Pointers)
Idea: For each index i, precompute the rightmost index j such that the subarray [i, j] is special.
Steps:
Use two pointers, i and j, to iterate through nums. Expand j until a violating index is found or the array ends.
Store the rightmost valid index for each i in validRightMostIdx.
For each query, check if the queried range [start, end] lies completely within [start, validRightMostIdx[start]].
Approach-3 (Using Binary Search)
Idea: Use a list of violating indices and perform a binary search to determine if any violating index exists within the query range.
Steps:
Identify and store all violating indices (where consecutive elements have the same parity) in a sorted list vi.
For each query, use binary search to check if any violating index exists in the range [start+1, end].
If no violating index is found, mark the subarray as special.
✨ Timelines✨
00:00 - Introduction
0:34 - Motivation
1:31 - Problem Explanation
7:36 - Approach-1 Thought Process
24:59 - Coding Approach-1
27:51 - Approach-2 Thought Process
41:13 - Coding Approach-2
44:30 - Approach-3 Thought Process
1:01:41 - Coding Approach-3
#MIK #mik #Mik
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik