< Ace Coding /> πŸš€
337 subscribers
54 photos
2 videos
95 files
66 links
Welcome to Ace Coding! Join us for tips, tutorials, and insights on coding and software engineering. Stay updated with the latest content and elevate your programming skills!Let's learn and grow together in the world of software engineering!
Download Telegram
the new keyword is used to create new objects or instances of a class. It is essential for memory allocation in Java, as it initializes objects dynamically during runtime.
what is the output of the ff.
String ace = "Ace Coding";
System.out.println(ace.startsWith('A');
System.out.println(ace.endsWith('g');
πŸ’» A2SV prep: Two pointers

🟒 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! πŸš€πŸŒŸ
πŸ‘2
βœ… 100% Yesified πŸ˜‚

Theory vs Practice

@AceCoding
😁4
πŸ’‘ 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
πŸ’» 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.

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! πŸš€πŸŒŸ