๐ฅ GFG POTD: Palindrome with Replacement
Replace '?' to form a palindrome while minimizing adjacent ASCII differences.
๐ง Two Pointers + Greedy
โฑ๏ธ O(n)
๐ป https://t.co/VQl7u8RN1P
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ฅ GFG POTD: Minimum Sum Subarray
Kadane's Algorithm, but for the minimum!
๐ง Track the minimum subarray ending at each index
โฑ๏ธ O(n) time | O(1) space
๐ป https://t.co/Oqnklonf82
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ฅ GFG POTD: Largest with Same Parity Adjacent Swaps
The key observation: elements of different parity cannot swap!
โ Group by parity
โ Sort each group in descending order
โฑ๏ธ O(n log n)
Link: https://t.co/Ne1NvVZtW1
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ฅ GFG POTD: Count Indices That Escape Array
Can you identify which indices eventually escape and which get trapped in cycles?
๐ง DFS + Cycle Detection
โฑ๏ธ O(n) time | O(n) space
๐ป https://t.co/wwNlEIPRbk
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ฅ GFG POTD: Convert One String to Another with Constraints
A moves left. B moves right. Neither can cross.
๐ง Two Pointers
โฑ๏ธ O(m+n) time
๐ป C++
๐ฅ Watch: https://t.co/3iYp6GUuCp
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ GFG POTD: Successful Binary Searches Irrespective of Pivot
The trick? Prefix Max + Suffix Min.
โ Identify elements guaranteed to be found
โฑ๏ธ O(n) time
๐ป C++
๐ฅ Watch: https://t.co/IjmBbJ5I3R
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ฅ GFG POTD: Maximum Without 3 Consecutive Set Bits
Can you maximize n without allowing 111 in binary?
Example: 7 โ 111 โ 110 โ 6
๐ง Greedy + Bit Manipulation
โฑ๏ธ O(log n)
๐ฅ Watch: https://t.co/8M63Kwm7fy
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ค GFG POTD: Roll Characters of String
Multiple prefix updates? Don't update every character for every operation!
โ Difference Array + Prefix Sum
โฑ๏ธ O(n + m)
๐ป C++ | Company: Airtel
๐ฅ Watch: https://t.co/JbAqjokd3Z
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
GFG POTD: Minimum Squares with Full Cuts
A simple Greedy Approach to minimize the number of squares.
โฑ๏ธ O(log(min(n, m)))
๐ป C++
Company Tag: Amazon
๐ Watch the full video: https://t.co/9Jg5bdtT7o
Code se zyada, Soch Samjho.
#DSA#GFGPOTD#100DaysOfCode
๐ฅ GFG POTD โ Maximum Frequency with K Increments
Sort the array โ maintain a sliding window โ make every element equal to arr[r].
๐ง Cost = target ร window_size โ window_sum
๐ฅ https://t.co/aFqIzxLJlB
Code se zyada, Soch Samjho. โค๏ธ
#GFGPOTD#DSA#Cpp#SlidingWindow
๐ฅ GFG POTD โ Max Path Sum Between Two Leaves
Classic Tree DP ๐ง
For every node:
๐ Return โ best root-to-leaf path
๐ฅ Update โ left + root + right
โฑ๏ธ O(N)
๐พ O(H)
๐ฅ https://t.co/k19mUiMtJV
Code se zyada, Soch Samjho. โค๏ธ
#GFGPOTD#DSA#Cpp#BinaryTree
๐ฅ GFG POTD โ Your Social Network
Each user points to a smaller-numbered user, so we can simply follow the friend links until reaching User 1.
๐ง Simple traversal
๐ป C++
โฑ๏ธ O(Nยฒ)
๐ฅ https://t.co/hmTGzYWOyc
Code se zyada, Soch Samjho. โค๏ธ
#GFGPOTD#DSA#Cpp
๐ฅ GFG POTD โ Lexicographically Smallest Rotation
How do you find the smallest rotation of a string in O(N)?
๐ Booth's Algorithm
๐ Compare two candidate rotations
๐ O(N) time
๐ฅ https://t.co/UR4rVlcszk
Code se zyada, Soch Samjho. โค๏ธ
#DSA#Strings#GFGPOTD#Cpp