2026 February7 Problems

33 views
Skip to first unread message

daryl...@gmail.com

unread,
Feb 7, 2026, 12:50:11 PM (5 days ago) Feb 7
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.

3174. Clear Digits Easy 82.6%




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

Anuj Patnaik

unread,
Feb 7, 2026, 12:56:27 PM (5 days ago) Feb 7
to leetcode-meetup
class Solution:
def clearDigits(self, s: str) -> str:
stack = []
for i in s:
if i.isnumeric():
if len(stack) > 0:
stack.pop()
else:
stack.append(i)
return "".join(stack)

Allen S.

unread,
Feb 7, 2026, 1:05:40 PM (5 days ago) Feb 7
to leetcode-meetup
func clearDigits(s string) string {
var b []rune
for _, v := range s {
if unicode.IsDigit(v) {
b = b[:len(b)-1]
} else {
b = append(b, v)
}
}
return string(b)
}
/*
[abc321]
[ab21]
[a1]
[]
*/

FloM

unread,
Feb 7, 2026, 1:24:19 PM (5 days ago) Feb 7
to leetcode-meetup
3174. Clear Digits Easy 82.6%
class Solution {
public:
string clearDigits(string s) {
deque<char> resultingNonDigits{};

int ii=0;
while( ii<s.size() )
{
if (s[ii] >= '0' && s[ii] <= '9')
{
resultingNonDigits.pop_back();
}
else
{
resultingNonDigits.push_back(s[ii]);
}
++ii;
}

string ans{};
while(!resultingNonDigits.empty())
{
ans += resultingNonDigits.front();
resultingNonDigits.pop_front();
}

return ans;
}
};

FloM

unread,
Feb 7, 2026, 1:50:42 PM (5 days ago) Feb 7
to leetcode-meetup
class Solution {
public:
string clearStars(string s) {
// Time: O(n*lg(n)), Mem: O(n)

// <char, int> is <letter, index>
// return the index of the smallest letter.
// if there is more than one index, return the largest index
priority_queue<
pair<char, int>,
vector<pair<char, int>>,
decltype([](const pair<char, int>&a, const pair<char, int>&b)
{
if (a.first == b.first)
{
return a.second < b.second;
}
return b.first < a.first;
})
> pq{};

unordered_set<int> deletedIndices{};

for(int ii=0; ii<s.size(); ++ii)
{
if (s[ii] == '*')
{
deletedIndices.insert(pq.top().second);
pq.pop();
}
else
{
pq.push({s[ii], ii});
}
}

string ans{};
for(int ii=0; ii<s.size(); ++ii)
{
if (!(s[ii] == '*' || deletedIndices.contains(ii)))
{
ans += s[ii];
}
}

return ans;
}
};

Allen S.

unread,
Feb 7, 2026, 2:15:26 PM (5 days ago) Feb 7
to leetcode-meetup
/*
- non pop vialations, so no mono Stack or mono Queue

input: ababc *** ab ****
output: bc
*/

func clearStars(s string) string {
b := make(map[int]bool) // chars to be removed from the original
var pq PriorityQueue
heap.Init(&pq)
for i := range s {
if s[i] != '*' {
heap.Push(&pq, &Item{s[i], i})
} else {
item := heap.Pop(&pq).(*Item)
b[item.index] = true
}
}
var res []byte
for i := range s {
if !b[i] && s[i] != '*' {
res = append(res, s[i])
}
}
return string(res)
}

type Item struct {
value byte
index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
if pq[i].value == pq[j].value {
return pq[i].index > pq[j].index
}
return pq[i].value < pq[j].value
}

func (pq PriorityQueue) Swap(i, j int) {
pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x any) {
item := x.(*Item)
*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() any {
old := *pq
n := len(old)
item := old[n-1]
*pq = old[0 : n-1]
return item
}

Jagrut

unread,
Feb 7, 2026, 2:31:57 PM (5 days ago) Feb 7
to leetcode-meetup
https://leetcode.com/problems/clear-digits/

class Solution:
def clearDigits(self, s: str) -> str:
st = []
for c in s:
if c.isdigit() and len(st) > 0:
st.pop()
else:
st.append(c)
return ''.join(st)


class Solution:
def clearStars(self, s: str) -> str:
cnt = [[] for _ in range(26)]
s_arr = list(s)
for i in range(len(s)):
c = s[i]
if c == '*':
for j in range(26):
if len(cnt[j]) > 0:
index_to_exclude = cnt[j].pop()
s_arr[index_to_exclude] = '*'
break
else:
index = ord(c) - ord('a')
cnt[index].append(i)
return ''.join(c for c in s_arr if c != '*')


saurabh s

unread,
Feb 7, 2026, 2:43:52 PM (5 days ago) Feb 7
to leetcod...@googlegroups.com
class Solution:
def clearDigits(self, s: str) -> str:
answer = []
for char in s:
if char.isdigit():
answer.pop()
else:
answer.append(char)
return "".join(answer)

--
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/1d5d9d93-b4f8-4591-b72f-b5a43ac07fd1n%40googlegroups.com.

Bhupathi Kakarlapudi

unread,
Feb 7, 2026, 3:24:42 PM (5 days ago) Feb 7
to leetcod...@googlegroups.com
class Solution:
def clearDigits(self, s: str) -> str:
alpha_stack:list[str] = []

for ch in s:
if ch.isdigit() and alpha_stack:
alpha_stack.pop()
else:
alpha_stack.append(ch)

return "".join(alpha_stack)

On Sat, Feb 7, 2026 at 9:50 AM daryl...@gmail.com <daryl...@gmail.com> wrote:
--

Carlos Green

unread,
Feb 11, 2026, 6:26:21 PM (14 hours ago) Feb 11
to leetcode-meetup
/**
* @param {string} s
* @return {string}

Approach:
1) Create a result array
2) Iterate over the input string
3) Create a set to hold all of the numbers
4) When we hit a number inside of the set, remove the leftmost element
5) Return the result string

Time O(n^2) Worst Case to shift elements
Space O(n)

var clearDigits = function(s) {
const result = s.split('')
const numbers = new Set('1234567890'.split(''))
console.log('result', result)

for (let i = 1; i < result.length; i++) {
if (numbers.has(result[i])) {
// console.log('result[i]', result[i - 1], result[i], i)
result.splice(i - 1, 2)
i-=2
// result.splice(i, 1)
}
}

if (numbers.has(result[0])) {
result.shift()
}

console.log('result', result)
return result.join('')
};


2nd Approach:
- Given that we know we just want to skip numbers we can

1) Create a count variable
2) Iterate backwards
3) Create a result string
4) Count how many numbers we have
5) Then skip over the corresponding characters

Time & Space O(n)
**/

var clearDigits = function(s) {
let result = ''
let count = 0
const numbers = new Set('1234567890'.split(''))

for (let i = s.length - 1; i >= 0; i--) {
if (numbers.has(s[i])) {
count++
} else if (count > 0) {
count--
} else {
result = s[i] + result
}
}

return result
}

Vivek Hajela

unread,
1:15 AM (8 hours ago) 1:15 AM
to leetcod...@googlegroups.com
************************************************************************************
3174. Clear Digits Easy 82.6%
************************************************************************************

Time Complexity : O(n)
Space complexity : O(n)

class Solution {
public:
    string clearDigits(string s) {

        stack<char> S;
        for (int i = 0; i < s.length(); i++) {

            if (!S.empty() && S.top() - 'a' >= 0 && S.top() - 'a' <= 25 &&
                s[i] - '0' >= 0 && s[i] - '0' <= 9) {
                S.pop();
            } else {
                S.push(s[i]);
            }
        }

        string result;
        while (!S.empty()) {
            result += S.top();
            S.pop();
        }
        std::reverse(result.begin(), result.end());
        return result;
    }
};

On Sat, Feb 7, 2026 at 9:50 AM daryl...@gmail.com <daryl...@gmail.com> wrote:
--

Vivek Hajela

unread,
2:16 AM (7 hours ago) 2:16 AM
to leetcod...@googlegroups.com
*************************************************************************************
*****************************************************************************************

class Solution {
public:
    //priority q comparator function sorted by char, if char is same, then
    // higher index (closer to '*') will be at the top
    struct comp {
        bool operator()(pair<int, char>& p1, pair<int, char>& p2) {
            if(p1.second == p2.second) {
                return p1.first < p2.first;
            } else {
                return p1.second > p2.second;
            }
        }
    };

    static bool comp1(const pair<int, char>& p1, const pair<int, char>& p2) {
        return p1.first < p2.first;
    }
    string clearStars(string s) {

        //make priority q of pair of indices and char
        priority_queue<pair<int, char>, vector<pair<int, char>>, comp> PQ;

        for (int i = 0; i < s.length(); i++) {
            if (s[i] != '*') {
                PQ.push({i, s[i]});
            } else {
                //whenver we see a '*', we delete the top of q
                if (!PQ.empty()) {
                    PQ.pop();
                }
            }
        } // for ends

        vector<pair<int, char>> output;
        //convert the PQ into vector
        while (!PQ.empty()) {
            output.push_back({PQ.top().first, PQ.top().second});
            PQ.pop();
        }
        //sort the vector based on indices
        sort(output.begin(), output.end(), comp1);
        string result;
        for (int i = 0; i < output.size(); i++) {
            result += output[i].second;
        }
        return result;
    }
};
 

On Sat, Feb 7, 2026 at 9:50 AM daryl...@gmail.com <daryl...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages