< 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
Which one of the following has NOT been a name for Java?
Anonymous Quiz
3%
a) Oak
14%
b) Green
5%
c) Java
78%
d) Tree
what is the output of the ff.
float x = 2.2;
long y = 100;
System.out.println(x + y);
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 💪🦾