2026 March 28 Problems

45 views
Skip to first unread message

daryl...@gmail.com

unread,
Mar 28, 2026, 12:53:46 PMMar 28
to leetcode-meetup
Feel free to work on any of the problems you want; we'll have people present their solutions at 11:30.

Please post your solutions to this thread so others can use this as a reference.

1768. Merge Strings Alternately Easy 82.1%


1782. Count Pairs Of Nodes Hard 42.7%

We're going to use the same Google meet link as the last few times: https://meet.google.com/xnn-kifj-jnx?pli=1

Allen S.

unread,
Mar 28, 2026, 1:05:15 PMMar 28
to leetcode-meetup
func mergeAlternately(word1 string, word2 string) string {
res := make([]byte, 0, len(word1) + len(word2))
for i := range max(len(word1), len(word2)) {
if i < len(word1) {
res = append(res, word1[i])
}
if i < len(word2) {
res = append(res, word2[i])
}
}
return string(res)
}

Anuj Patnaik

unread,
Mar 28, 2026, 1:06:49 PMMar 28
to leetcode-meetup
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
i = 0
j = 0
final_str = ""
while i < len(word1) and j < len(word2):
final_str += word1[i]
final_str += word2[j]
i += 1
j += 1
if len(word1[i:]) >= 1:
final_str += word1[i:]
else:
if len(word2[j:]) >= 1:
final_str += word2[j:]
return final_str

Allen S.

unread,
Mar 28, 2026, 1:24:03 PMMar 28
to leetcode-meetup
func minimumLength(s string) int {
l, r := 0, len(s)-1
for l < r && s[l] == s[r] {
c := s[l]
for l <= r && s[l] == c { // skip from left side
l++
}
for l <= r && s[r] == c { // skip form right side
r--
}
}
return r - l + 1
}

Wang Lijun

unread,
Mar 28, 2026, 1:40:21 PMMar 28
to leetcode-meetup
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
n1 = len(word1)
n2 = len(word2)
res = ""
i = 0
j = 0
for r in range(n1 + n2):
if r % 2 == 0:
# pick from word1, i += 1
if i < len(word1):
res += word1[i]
i+=1
else:
res += word2[j:]
return res
else:
# pick from word2, j+=1
if j < len(word2):
res += word2[j]
j+=1
else:
res += word1[i:]
return res
return res
On Saturday, March 28, 2026 at 9:53:46 AM UTC-7 daryl...@gmail.com wrote:

Jagrut

unread,
Mar 28, 2026, 1:48:55 PMMar 28
to leetcode-meetup

class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
res = []
limit = min(len(word1), len(word2))
for i in range(limit):
res.append(word1[i])
res.append(word2[i])
if len(word1) != len(word2):
longer = word1 if len(word1) > len(word2) else word2
for i in range(limit, len(longer)):
res.append(longer[i])
return ''.join(res)

Anuj Patnaik

unread,
Mar 28, 2026, 1:49:30 PMMar 28
to leetcode-meetup
class Solution:
def minimumLength(self, s: str) -> int:
i = 0
j = len(s) - 1
while i < j and s[i] == s[j]:
prefix = s[i]
while i <= j and s[i] == prefix:
i += 1
while i <= j and s[j] == prefix:
j -= 1
return j - i + 1

Bhupathi Kakarlapudi

unread,
Mar 28, 2026, 1:58:45 PMMar 28
to leetcod...@googlegroups.com
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
merged:str = ""

word1_len = len(word1)
word2_len = len(word2)

i = 0
while(word1_len > 0 or word2_len > 0):
if word1_len > 0:
merged += f"{word1[i]}"
if word2_len > 0:
merged += f"{word2[i]}"
i += 1
word1_len -= 1
word2_len -= 1

return merged

--
whatspp group: http://whatsapp.techbayarea.us/
---
You received this message because you are subscribed to the Google Groups "leetcode-meetup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leetcode-meet...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/leetcode-meetup/e18475d2-51b8-4030-b117-bf2448215385n%40googlegroups.com.

Wang Lijun

unread,
Mar 28, 2026, 2:05:06 PMMar 28
to leetcode-meetup
class Solution:
def minimumLength(self, s: str) -> int:
if not s:
return 0
l = 0
r = len(s)-1
while l <= r:
if l == r:
return 1
if s[l] != s[r]:
return r - l + 1
else:
while l <= r and l+1 < len(s) and s[l] == s[l+1]:
l+=1
while l <= r and r-1 >= 0 and s[r] == s[r-1]:
r -= 1
l +=1
r -=1
return 0

vinay

unread,
Mar 28, 2026, 2:34:36 PMMar 28
to leetcod...@googlegroups.com
time O(N) / used two pointer approach

class Solution {
    public int minimumLength(String s) {
       
        int i = 0, j = s.length()-1;

        while(i < j){
            char c = s.charAt(i);
            char t = s.charAt(j);

            if(c == t){
                while(i < j && s.charAt(i) == s.charAt(i+1)){
                    i++;
                }
                while(i < j && s.charAt(j) == s.charAt(j-1)){
                    j--;
                }
            }else{
                break;
            }
            i++;
            j--;
        }

        return Math.max(0, j - i + 1);
    }
}

vinay

unread,
Mar 28, 2026, 2:35:54 PMMar 28
to leetcod...@googlegroups.com
1768. Merge Strings Alternately Easy 82.1%
time O(N)
class Solution {
    public String mergeAlternately(String word1, String word2) {
        int i = 0, j = 0;
        StringBuilder sb = new StringBuilder();

        while(i < word1.length() && j < word2.length()){
            sb.append(word1.charAt(i));
            sb.append(word2.charAt(j));
            i++;
            j++;
        }
        while(i < word1.length()){
            sb.append(word1.charAt(i));
            i++;
        }
        while(j < word2.length()){
            sb.append(word2.charAt(j));
            j++;
        }

        return sb.toString();
    }
}

Bhupathi Kakarlapudi

unread,
Mar 28, 2026, 2:57:43 PMMar 28
to leetcod...@googlegroups.com
class Solution:
def minimumLength(self, s: str) -> int:
min:int = 0

while(len(s) > 1 ):
s_len = len(s)

if (s[0] != s[s_len-1]):
return s_len
else:
ch_rmv:str = s[0]
s = s.strip(ch_rmv)


return len(s)

Anuj Patnaik

unread,
Mar 28, 2026, 3:31:42 PMMar 28
to leetcode-meetup

class Solution:
def countPairs(self, n, edges, queries):
edges_count = [0] * n
intersect_dict = defaultdict(int)
for i in edges:
u = i[0]
v = i[1]
edges_count[u - 1] += 1
edges_count[v - 1] += 1
if u > v:
temp = u
u = v
v = temp
intersect_dict[(u, v)] += 1
sorted_edges_count = sorted(edges_count)
answers = []
for curr in queries:
count = 0
left = 0
right = n - 1
while left < right:
if sorted_edges_count[left] + sorted_edges_count[right] > curr:
count += right - left
right -= 1
else:
left += 1
for i in intersect_dict:
u = i[0]
v = i[1]
common = intersect_dict[i]
u_edge = u - 1
v_edge = v - 1
if edges_count[u_edge] + edges_count[v_edge] > curr and edges_count[u_edge] + edges_count[v_edge] - common <= curr:
count -= 1
answers.append(count)
return answers
Reply all
Reply to author
Forward
0 new messages