0% found this document useful (0 votes)
14 views19 pages

STL Level 2 DPP 01 Discussion Notes

The document contains discussion notes on various topics related to C++ programming, specifically focusing on data structures and algorithms. Key problems covered include finding the longest consecutive sequence in an array, reversing words in a string, removing duplicates from a sorted array, and checking for valid anagrams. Each problem is accompanied by example inputs and outputs to illustrate the concepts.

Uploaded by

sachin55443gg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views19 pages

STL Level 2 DPP 01 Discussion Notes

The document contains discussion notes on various topics related to C++ programming, specifically focusing on data structures and algorithms. Key problems covered include finding the longest consecutive sequence in an array, reversing words in a string, removing duplicates from a sorted array, and checking for valid anagrams. Each problem is accompanied by example inputs and outputs to illustrate the concepts.

Uploaded by

sachin55443gg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

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

You might also like