๐ป A2SV prep: Two pointers
๐ข Two sum
๐ก Two sum ll input array is sorted
๐The above two are easy; warm up
๐ก 3sum Click here
Solution:
๐ก 3sum closest :- click here
Solution:
๐ก 4Sum :- click here
Solution:
๐๐ @AceCoding Presents! ๐๐
๐ข Two sum
๐ก Two sum ll input array is sorted
๐The above two are easy; warm up
๐ก 3sum Click here
Solution:
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
res = []
nums.sort()
n = len(nums)
for i in range(n-2):
if nums[i] > 0:
break
if i > 0 and nums[i] == nums[i-1]:
continue
L, R = i + 1, n - 1
while L < R:
sum = nums[i] + nums[L] + nums[R]
if sum == 0:
res.append([nums[i], nums[L], nums[R]])
L +=1
R -=1
while L < R and nums[L] == nums[L-1]:
L += 1
while L < R and nums[R] == nums[R+1]:
R -= 1
elif sum > 0:
R -= 1
else:
L += 1
return res
๐ก 3sum closest :- click here
Solution:
python
class Solution:
def threeSumClosest(self, nums: List[int], target: int) -> int:
nums.sort()
res = sum(nums[:3])
for i in range(len(nums)):
L, R = i+1, len(nums)-1
while L < R:
closest = nums[i] + nums[L] + nums[R]
if abs(target - closest) < abs(target - res):
res = closest
if closest > target:
R -= 1
elif closest < target:
L += 1
else:
return closest
return res
๐ก 4Sum :- click here
Solution:
class Solution:
def fourSum(self, nums: List[int], target: int) -> List[List[int]]:
nums.sort()
n = len(nums)
res = []
for i in range(n-3):
if i > 0 and nums[i] == nums[i-1]:
continue
for j in range(i+1, n-2):
if j > i+1 and nums[j] == nums[j-1]:
continue
L, R = j + 1, n - 1
while L < R:
four_sum = nums[i] + nums[j] + nums[L] + nums[R]
if four_sum == target:
res.append([nums[i], nums[j], nums[L], nums[R]])
L += 1
R -= 1
while L < R and nums[L] == nums[L-1]:
L += 1
while L < R and nums[R] == nums[R+1]:
R -= 1
elif four_sum > target:
R -= 1
else:
L += 1
return res
๐๐ @AceCoding Presents! ๐๐
LeetCode
Two Sum - LeetCode
Can you solve this real interview question? Two Sum - You are given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and youโฆ
You may assume that each input would have exactly one solution, and youโฆ
๐2
๐ก Which side are you rocking, Theory or Practice. [Right or Left]
Anonymous Poll
18%
๐ Theory Master ๐
50%
๐ Practice Pro ๐ป
32%
๐ฅ Both Boss ๐ช๐ฆพ
Forwarded from A2SV - Community
๐จ A2SV G6 Remote Education Recruitment Update ๐จ
Itโs been an incredible journey since we began interviewing candidates for G6 Remote Education. After posting the application form, we were overwhelmed by the sheer number of applications! ๐
Weโre committed to reviewing every application fairly. Due to limited interview slots, only applicants with the highest grades will proceed to the interview stage, and invitations will be sent out soon.
For those who have already completed their interviews, your interviews are being graded. The final results for all applicants will be released in three weeks, once the entire process is concluded.
Thank you for your patience and the effort youโve put into this journey. ๐
#A2SV #RemoteEducation #RecruitmentUpdate
Itโs been an incredible journey since we began interviewing candidates for G6 Remote Education. After posting the application form, we were overwhelmed by the sheer number of applications! ๐
Weโre committed to reviewing every application fairly. Due to limited interview slots, only applicants with the highest grades will proceed to the interview stage, and invitations will be sent out soon.
For those who have already completed their interviews, your interviews are being graded. The final results for all applicants will be released in three weeks, once the entire process is concluded.
Thank you for your patience and the effort youโve put into this journey. ๐
#A2SV #RemoteEducation #RecruitmentUpdate
๐ป A2SV prep: Two pointers
๐ข 1995. Count Special Quadruplets
Solution: This is a good example of questions with a small amount of input, or constraints that can be solved using a simple brute force.
๐ก 454. 4Sum II
Intuition : from the first two arrays find the count of sum of paris in nums1 and nums2 next get the compliment from the last two arrays nums3 and nums4
๐๐ @AceCoding Presents! ๐๐
๐ข 1995. Count Special Quadruplets
Solution: This is a good example of questions with a small amount of input, or constraints that can be solved using a simple brute force.
class Solution:
def countQuadruplets(self, nums: List[int]) -> List[List[int]]:
res = 0
n = len(nums)
for i in range(n-3):
for j in range(i+1, n-2):
for k in range(j +1, n-1):
for l in range(k +1,n):
if nums[i] + nums[k] + nums[j] - nums[l] == 0:
res += 1
return res
๐ก 454. 4Sum II
Intuition : from the first two arrays find the count of sum of paris in nums1 and nums2 next get the compliment from the last two arrays nums3 and nums4
class Solution:
def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:
sum_count = Counter(a + b for a in nums1 for b in nums2)
count = 0
for c in nums3:
for d in nums4:
complement = -(c + d)
count += sum_count.get(complement, 0)
return count
๐๐ @AceCoding Presents! ๐๐
LeetCode
Count Special Quadruplets - LeetCode
Can you solve this real interview question? Count Special Quadruplets - Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:
* nums[a] + nums[b] + nums[c] == nums[d], and
* a < b < c < d
Example 1:โฆ
* nums[a] + nums[b] + nums[c] == nums[d], and
* a < b < c < d
Example 1:โฆ
๐ป A2SV prep: Sliding window problem
๐ก 1248. Count Number of Nice Subarrays
Intuition: we want to find the count of the subarrays with exactly k odd numbers so our window should have exactly k odd numbers. To get the exact count we can just count the number of sub arrays with at most k odd numbers and subtract the count of sub arrays with at most k - 1 odd numbers which will give us the count of substrings with exact k odd numbers in it.
๐๐ @AceCoding Presents! ๐๐
๐ก 1248. Count Number of Nice Subarrays
Intuition: we want to find the count of the subarrays with exactly k odd numbers so our window should have exactly k odd numbers. To get the exact count we can just count the number of sub arrays with at most k odd numbers and subtract the count of sub arrays with at most k - 1 odd numbers which will give us the count of substrings with exact k odd numbers in it.
class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
def atMost(k):
count = 0
L, R = 0, 0
for R in range(len(nums)):
if nums[R] % 2 != 0:
k -= 1
while k < 0:
if nums[L] % 2 != 0:
k += 1
L += 1
count += R - L + 1
return count
return atMost(k) - atMost(k-1)
๐๐ @AceCoding Presents! ๐๐
LeetCode
Count Number of Nice Subarrays - LeetCode
Can you solve this real interview question? Count Number of Nice Subarrays - Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Input:โฆ
Return the number of nice sub-arrays.
Example 1:
Input:โฆ
๐ฅ This 3D website is crazy. check it out.
โ๏ธBuilt with React.js and Three.js
๐ https://bfcm.shopify.com
@AceCoding
โ๏ธBuilt with React.js and Three.js
๐ https://bfcm.shopify.com
@AceCoding
๐ฅ5
๐ป A2SV prep: Sliding window problem
๐ก 3. Longest Substring Without Repeating Characters
๐๐ @AceCoding Presents! ๐๐
๐ก 3. Longest Substring Without Repeating Characters
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
maxlen = 0
L = R = 0
hashset = set()
while R < len(s):
if s[R] in hashset:
maxlen = max(maxlen, R - L) # maxlen = max(maxlen, len(hashset))
while s[L] != s[R]:
hashset.remove(s[L])
L += 1
L += 1
hashset.add(s[R])
R += 1
maxlen = max(maxlen, R - L)
return maxlen
๐๐ @AceCoding Presents! ๐๐
LeetCode
Longest Substring Without Repeating Characters - LeetCode
Can you solve this real interview question? Longest Substring Without Repeating Characters - Given a string s, find the length of the longest substring without duplicate characters.
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answerโฆ
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answerโฆ
๐จ Exciting News Alert! ๐จ
๐ Big Congrats to the December 2024 Scholarship Winners! ๐
๐ 60 incredible talents from Ethiopia have been awarded this golden opportunity to dive into the tech world and build a brighter future! ๐ป๐
๐ Donโt keep it to yourself! Share this announcement with your friends and familyโlet them celebrate with you and get inspired! ๐โจ
#EvangadiTech #ScholarshipWinners #FutureInTech
Join ๐๐๐
๐๐ @AceCoding Presents! ๐๐
๐ The list of Evangadi Fullstack MERN Stack Scholarship Winners for the December 2024 Batch is out! ๐โจ
๐ Big Congrats to the December 2024 Scholarship Winners! ๐
๐ 60 incredible talents from Ethiopia have been awarded this golden opportunity to dive into the tech world and build a brighter future! ๐ป๐
๐ Winners: Congratulations on this amazing milestone! Celebrate your hard work and dedication. ๐๐
๐ Donโt keep it to yourself! Share this announcement with your friends and familyโlet them celebrate with you and get inspired! ๐โจ
#EvangadiTech #ScholarshipWinners #FutureInTech
Join ๐๐๐
๐๐ @AceCoding Presents! ๐๐
๐5๐1
Forwarded from A2SV - Community
๐ข Announcement: A2SV G6 In-Person Application Update
Dear Applicants,
Thank you for submitting your applications for the A2SV G6 recruitment process. After carefully reviewing all submissions, we are excited to announce that the shortlist of candidates selected for interviews will be shared very soon! ๐ Please check your emails regularly for updates. ๐ง
Starting Monday, shortlisted candidates will be able to schedule their technical interviews. ๐
We highly recommend that you begin preparing for the technical interview to ensure your success. ๐ The key topics to focus on include:
- Sorting
- Two Pointers
- Prefix Sum
- Sliding Window
- Stack & Queues
Best of luck to all applicants, and we look forward to meeting you during the interview process! ๐ช
Sincerely,
The A2SV Team
Dear Applicants,
Thank you for submitting your applications for the A2SV G6 recruitment process. After carefully reviewing all submissions, we are excited to announce that the shortlist of candidates selected for interviews will be shared very soon! ๐ Please check your emails regularly for updates. ๐ง
Starting Monday, shortlisted candidates will be able to schedule their technical interviews. ๐
We highly recommend that you begin preparing for the technical interview to ensure your success. ๐ The key topics to focus on include:
- Sorting
- Two Pointers
- Prefix Sum
- Sliding Window
- Stack & Queues
Best of luck to all applicants, and we look forward to meeting you during the interview process! ๐ช
Sincerely,
The A2SV Team