2025 June 14 Problems

78 views
Skip to first unread message

daryl...@gmail.com

unread,
Jun 14, 2025, 12:44:28 PMJun 14
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.

Hard problem has been rolled over from last week.



3484. Design Spreadsheet Medium 67.7%

  3337. Total Characters in String After Transformations II Hard 58.3%


Please download and import the following iCalendar (.ics) files to your calendar system.

Samuel Yor

unread,
Jun 14, 2025, 12:48:12 PMJun 14
to leetcod...@googlegroups.com
Alright thanks 

--
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/27b27c49-3ba0-40a3-9e6d-c6c80cdac7d4n%40googlegroups.com.

Anuj Patnaik

unread,
Jun 14, 2025, 12:57:45 PMJun 14
to leetcode-meetup
class Solution:
def convertDateToBinary(self, date: str) -> str:
ymd = date.split("-")
ymd_binary = []
for i in ymd:
ymd_binary.append((bin(int(i)).replace("0b","")))
return ymd_binary[0] + "-" + ymd_binary[1] + "-" + ymd_binary[2]

Tarini Pattanaik

unread,
Jun 14, 2025, 1:19:56 PMJun 14
to leetcod...@googlegroups.com
public String convertDateToBinary(String date) {
String year = date.substring(0,4);
String month = date.substring(5, 7);
String day = date.substring(8, 10);

String ans = stringToBinary(year) + "-" + stringToBinary(month) + "-" + stringToBinary(day);
return ans;
}

String stringToBinary(String str) {
int n = Integer.parseInt(str);
String ans = "";
while (n > 0) {
ans = ((n % 2 == 0) ? "0" : "1") + ans;
n /= 2;
}

return ans;
}
}

Anuj Patnaik

unread,
Jun 14, 2025, 1:55:12 PMJun 14
to leetcode-meetup
class Spreadsheet:
def __init__(self, rows: int):
self.initialspreadsheet = [[0] * 26 for _ in range(rows)]

def setCell(self, cell: str, value: int) -> None:
cell_char = cell[0]
cell_num = int(cell[1:len(cell)])
index = ord(cell_char) - ord('A')
self.initialspreadsheet[cell_num - 1][index] = value

def resetCell(self, cell: str) -> None:
cell_char = cell[0]
cell_num = int(cell[1: len(cell)])
index = ord(cell_char) - ord('A')
self.initialspreadsheet[cell_num - 1][index] = 0
def getValue(self, formula: str) -> int:
parts = formula.replace("=", "").split("+")
sum = 0
for part in parts:
if part.isdigit():
sum += int(part)
else:
cell_char = ord(part[0]) - ord('A')
cell_num = int(part[1:])
sum += self.initialspreadsheet[cell_num -1][cell_char]
return sum

Anish Mangla

unread,
Jun 14, 2025, 2:04:35 PMJun 14
to leetcode-meetup
Is there any Imessage / Discord / Whatsapp or any other group too ?

Allen S.

unread,
Jun 14, 2025, 2:11:10 PMJun 14
to leetcode-meetup
func convertDateToBinary(date string) string {
res := ""
for _, v := range strings.Split(date, "-") {
if len(res) > 0 {
res += "-"
}
num, _ := strconv.Atoi(v)
res += fmt.Sprintf("%b", num)
}
return res
}

Gowrima Jayaramu

unread,
Jun 14, 2025, 2:16:07 PMJun 14
to leetcode-meetup
class Solution:
def convertDateToBinary(self, date: str) -> str:
date_ = date.split('-')
result = ''

for i in range(len(date_)):
# convert date_[i] to binary
res = ''

cur = int(date_[i])

while cur > 0:
res += str(cur%2)
cur = cur//2
result = result + res[::-1] + '-'
return result[:-1]


Sharad Bagri

unread,
Jun 14, 2025, 2:24:47 PMJun 14
to leetcod...@googlegroups.com
This solution passes 529/536 cases. For others it gives a time limit exceeded. It is O(T) solution. I see the suggested solution has something with matrix multiplication, that should pass all cases.
 
import collections
import copy

class Solution:
def lengthAfterTransformations(self, s: str, t: int, nums: List[int]) -> int:
ord_z = ord('z')
ord_a = ord('a')

def get_next_string(a_char):
n_chars = nums[ord(a_char) - ord_a]
next_chars = []
for i in range(1, n_chars+1):
next_char = ord(a_char) + i
if next_char > ord_z:
next_char -= 26
next_chars.append(chr(next_char))
return next_chars
init_dict = collections.Counter(s)
next_str_dict = dict()
for _ in range(t):
next_dict = defaultdict(int)
for a_char in init_dict:
if a_char in next_str_dict:
next_str = next_str_dict[a_char]
else:
next_str = get_next_string(a_char)
next_str_dict[a_char] = next_str
# print(f"{a_char}: {next_str}")
for n_char in next_str:
next_dict[n_char] += init_dict[a_char]
init_dict = next_dict
return sum(init_dict.values()) % (10**9 + 7)

 

Please download and import the following iCalendar (.ics) files to your calendar system.

--
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/27b27c49-3ba0-40a3-9e6d-c6c80cdac7d4n%40googlegroups.com.

--
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.

--
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.

Tarini Pattanaik

unread,
Jun 14, 2025, 2:28:27 PMJun 14
to leetcod...@googlegroups.com
3484. Design Spreadsheet class Spreadsheet {

int arr[][];
int rows = 0;
public Spreadsheet(int rows) {
arr = new int[rows + 1][26];
this.rows = rows + 1;
}
public void setCell(String cell, int value) {
int col = cell.charAt(0) - 'A';
int row = Integer.valueOf(cell.substring(1));
if (row >= rows) {
return;
}

arr[row][col] = value;
}
public void resetCell(String cell) {
int col = cell.charAt(0) - 'A';
int row = Integer.valueOf(cell.substring(1));

if (row >= rows) {
return;
}

arr[row][col] = 0;
}
public int getValue(String formula) {
//=A1+B2
//=5+7
int equalIndex = formula.indexOf('=');
int plusIndex = formula.indexOf('+');
String op1 = formula.substring(equalIndex + 1, plusIndex);
String op2 = formula.substring(plusIndex + 1);
char char1 = op1.charAt(0);
int val1 = 0;
if (char1 >= 'A' && char1 <= 'Z') {
int row1 = Integer.valueOf(op1.substring(1));
if (row1 >= rows) {
return 0;
}

val1 = arr[row1][char1 - 'A'];
} else {
val1 = Integer.valueOf(op1);
}

char char2 = op2.charAt(0);
int val2 = 0;
if (char2 >= 'A' && char2 <= 'Z') {
int row2 = Integer.valueOf(op2.substring(1));
if (row2 >= rows) {
return 0;
}
val2 = arr[row2][char2 - 'A'];
} else {
val2 = Integer.valueOf(op2);
}
return val1 + val2;
}
}

/**
* Your Spreadsheet object will be instantiated and called as such:
* Spreadsheet obj = new Spreadsheet(rows);
* obj.setCell(cell,value);
* obj.resetCell(cell);
* int param_3 = obj.getValue(formula);
*/

satyajit vegesna

unread,
Jun 14, 2025, 2:46:49 PMJun 14
to leetcod...@googlegroups.com
def __init__(self, rows: int):
#sheet = [ [0] * 26 ] * rows --- NEVER USE THIS WAY
sheet = [[0] * 26 for _ in range(rows)]
#[0] * 26 creates a list of 26 zeros. ✅
#[[0] * 26] * rows replicates that same inner list REFERENCE rows times.
self.sheet = sheet

def setCell(self, cell: str, value: int) -> None:
p1 = self.parse_format(cell)[0]
self.sheet[p1[0]][p1[1]] = value

def resetCell(self, cell: str) -> None:
self.setCell(cell, 0)

def getValue(self, formula: str) -> int:
operands = formula.split("+")
first_val = operands[0].replace("=", "")
sec_val = operands[1]
val1_p = self.parse_format(first_val)
val2_p = self.parse_format(sec_val)
val1 = val1_p[1] if val1_p[0] is None else self.sheet[val1_p[0][0]][val1_p[0][1]]
val2 = val2_p[1] if val2_p[0] is None else self.sheet[val2_p[0][0]][val2_p[0][1]]
return int(val1) + int(val2)
#return self.parse_format(first_val)[0][0] + self.parse_format(sec_val)[0][1]

def parse_format(self, str1: str):
if str1.isnumeric():
return None, int(str1)
else:
col = int(ord(str1[0]) - ord('A'))
row = int(str1[1:])
return (row-1, col-1), self.sheet[row-1][col-1]

Allen S.

unread,
Jun 14, 2025, 3:30:05 PMJun 14
to leetcode-meetup
// hash map solution type Spreadsheet struct {
data map[string]int
}


func Constructor(rows int) Spreadsheet {
data := make(map[string]int)
return Spreadsheet{data: data}
}


func (this *Spreadsheet) getNum (s string) int {
if num, err := strconv.Atoi(s); err == nil {
return num
}

return this.data[s]
}


func (this *Spreadsheet) SetCell(cell string, value int) {
this.data[cell] = value
}


func (this *Spreadsheet) ResetCell(cell string) {
this.data[cell] = 0
}


func (this *Spreadsheet) GetValue(formula string) int {
terms := strings.Split(formula[1:], "+")
return this.getNum(terms[0]) + this.getNum(terms[1])
}


/**
* Your Spreadsheet object will be instantiated and called as such:
* obj := Constructor(rows);
* obj.SetCell(cell,value);
* obj.ResetCell(cell);
* param_3 := obj.GetValue(formula);
*/

Samuel Yor

unread,
Jun 15, 2025, 6:41:50 PMJun 15
to leetcod...@googlegroups.com

Samuel Yor

unread,
Jun 15, 2025, 6:51:51 PMJun 15
to leetcod...@googlegroups.com
Late work

Gowrima Jayaramu

unread,
Jun 16, 2025, 11:51:35 AMJun 16
to leetcode-meetup
class Spreadsheet:

def __init__(self, rows: int):
self.spreadsheet = defaultdict(list)

new_rows = rows + 1

for i in range(65, 91):
self.spreadsheet[chr(i)] = [0] * new_rows
def setCell(self, cell: str, value: int) -> None:
col = cell[0]
row = int(cell[1:])

self.spreadsheet[col][row] = value

def resetCell(self, cell: str) -> None:
col = cell[0]
row = int(cell[1:])

self.spreadsheet[col][row] = 0

def getValue(self, formula: str) -> int:
formula_arr = formula[1:].split('+')
result = 0

def get_value_helper(cell: str):
row = cell[0]
col = int(cell[1:])

return int(self.spreadsheet[row][col])

# '=5+7'
if formula_arr[0].isdigit() and formula_arr[1].isdigit():
result = int(formula_arr[0]) + int(formula_arr[1])
elif formula_arr[0].isdigit():
# get row and col from formula_arr[1]
val = get_value_helper(formula_arr[1])
result = int(formula_arr[0]) + val

elif formula_arr[1].isdigit():
# get row and col from formula_arr[0]
val = get_value_helper(formula_arr[0])
result = int(formula_arr[1]) + val
else:
val1 = get_value_helper(formula_arr[0])
val2 = get_value_helper(formula_arr[1])

result = val1 + val2

return result

# Your Spreadsheet object will be instantiated and called as such:
# obj = Spreadsheet(rows)
# obj.setCell(cell,value)
# obj.resetCell(cell)
# param_3 = obj.getValue(formula)

On Saturday, 14 June 2025 at 09:44:28 UTC-7 daryl...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages