CS & IT
ENGINEERING
C++ WITH OOPS
STL Level - 2
DPP – 01 Discussion Notes By- Aditya sir
Recap of Previous Lecture
Topic Stack
soon
BinarySearch
Topics to be Covered
Topic Deque
oat
DPP 2 Discussion
3
Longest Consecutive Sequence in an Array
Problem Statement:
Given an unsorted array of integers nums, return the length of the longest
consecutive elements sequence.
Example 1:
Input: nums = [100, 4, 200, 1, 3, 2]
Output: 4
o
Explanation: The longest consecutive sequence is [1, 2, 3, 4], so return 4.
11,21311
Sequence
APPI Longest Consecutive
doesn't matter
ordering
3
A 2,6 1,9 4,5
am 6
1 34,56
3,2
A 100 4,200,1
lost 1,2 3,4 100,200
I 2 5
count ans
V
for i L n i
if a il a i 1 1
um
count
3
this count I
3
ans max am count
1
Reverse Words in a String
Problem Statement:
Given a string s, reverse the order of the words.
Example 1:
our
Input: s = "the sky is blue"
Output: "blue is sky the"
Soln the is blue
sky
word
if C
word C
is blue
the sky
5 O
for i n 1
Stv i
S
blue_is_sky_the
Remove Duplicates from Sorted Array
Problem Statement:
Given an integer array nums sorted in non-decreasing order, remove the duplicates
in-place and return the new length.
Example 1:
Input: nums = [1,1,2]
11 2
Output: 2 (nums = [1,2,_])
D
we
API
i.T3,3,3
W
o
P 1,2 3,5
0
retur
I
j I
Falis a i i
a a i
j
3 5ᵗʰ
Find the First Unique Character in a String
Problem Statement:
Given a string s, find the first non-repeating character and return its index.
Example 1:
Input: s = "leetcode"
s
acnode
Output: 0 aditya
cheer 11
a a
States 26 0
Status c a
z
25
426ᵗʰ char 25
EDIT
11 1,0 2,31
Rotate an Array
Problem Statement:
Given an array, rotate the array to the right by k steps.
Example 1:
Input: nums = [1,2,3,4,5,6,7], k = 3 To
Output: [5,6,7,1,2,3,4]
into
1234567
o I
Cases
765 21
5676
Merge Two Sorted Arrays
Problem Statement:
Ap
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as
one sorted array.
Example 1:
And
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5,6]
II
Check if a String is a Valid Anagram
Problem Statement:
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
Example 1:
Input: s = "anagram", t = "nagaram"
Output: true
API SI anagram
52 naagmar
anagram
aaagmnr anagrams
19 mar
anagmno
0
1
µ
THANK - YOU