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');
for the above
Anonymous Quiz
67%
true, true
8%
true, false
14%
false, false
0%
false, true
11%
Error
π» 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:β¦