📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
楼主: snowymo
跳转到指定楼层
上一主题 下一主题
收起左侧

冬令时个人打卡贴

🔗
 楼主| snowymo 2020-11-9 14:42:25 来自APP | 只看该作者
全局:
yt.sssun 发表于 2020-11-08 01:25:54
同从每月刷题打卡贴过来。没有帖子了好不适应,于是我也自己开了一贴自行记录。楼主加油。 (P.S. 发现好像这个贴不能给点赞加大米。。。所以是因为刷题打卡贴大家大米涨的太快影响卖会员的业绩了嘛)
我发现连回帖都没有提醒的 可能这个版直接禁止了加米等一系列操作 其实非常讽刺
你也加油(๑•̀ㅂ•́)و✧
回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-9 14:52:13 | 只看该作者
全局:
Day 25 Daily + freq

Daily 563. Binary Tree Tile

Calculate the sum first recursively. (DFS)
Calculate the diff btw left child and right child and add it to global result. (DFS)

227. Basic Calculator II

General using the stack idea.
I have one stack for numbers and the other one for operators
If it is + or -, I push to the stack, if it is * or /, I retrieve top from stack of numbers and calculate the result.
Second pass is to calculate the result of + and -.

The code could be briefer like treating + and - as sign of numbers directly. So we only have * and / operators and just do the calculation. Lastly calculate the numbers in the stack so we only need one stack then.

162. Find Peak Element

Even watch the MIT video I still did not get why the binary search idea is correct.

529. Minesweeper

Love minesweeper!
Basically recursion.
figure out the neighbours when itself is 'B' aka '0' mines around.

32. Longest Valid Parentheses

I have "left view" and "right view" in my mind.
so first run from left to right to see if ( is more than ), keep going until the end of the string so we have a couple of range that # of ( is larger than # of right.
Next, do the reversed thing to each range so the range of range should have equal # of left and right.
I store the number of each range by map. Other data structures are fine too.

Keep going!
回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-9 14:52:21 | 只看该作者
全局:
Day 25 Daily + freq

Daily 563. Binary Tree Tile

Calculate the sum first recursively. (DFS)
Calculate the diff btw left child and right child and add it to global result. (DFS)

227. Basic Calculator II

General using the stack idea.
I have one stack for numbers and the other one for operators
If it is + or -, I push to the stack, if it is * or /, I retrieve top from stack of numbers and calculate the result.
Second pass is to calculate the result of + and -.

The code could be briefer like treating + and - as sign of numbers directly. So we only have * and / operators and just do the calculation. Lastly calculate the numbers in the stack so we only need one stack then.

162. Find Peak Element

Even watch the MIT video I still did not get why the binary search idea is correct.

529. Minesweeper

Love minesweeper!
Basically recursion.
figure out the neighbours when itself is 'B' aka '0' mines around.

32. Longest Valid Parentheses

I have "left view" and "right view" in my mind.
so first run from left to right to see if ( is more than ), keep going until the end of the string so we have a couple of range that # of ( is larger than # of right.
Next, do the reversed thing to each range so the range of range should have equal # of left and right.
I store the number of each range by map. Other data structures are fine too.

Keep going!
回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-9 14:53:04 | 只看该作者
全局:
Day 25 Daily + freq
Why my replies require review?











回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-10 16:55:23 | 只看该作者
全局:
Day 26 Daily + High Freq


Daily 1026. Max diff btw ancestor and the current node

Very typical recursion + tree question

347. Top K Freq Elements

I am using the classic map + priority_queue solution.
Need to figure out how to do quick selection here.

692. Top K Freq Words

Very similar to the last question. I used the same solution and adjust based on the details of the question
Same. Need to figure out the quick selection solution. Partial sorting is important.

515. Find Largest Values

Row scan. Tree+queue

1.Two sum

Don't know why the time becomes so high after one year.

Keep fighting.
回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-11 16:34:47 | 只看该作者
全局:
Day 27 Daily + high freq
Did pony.ai interview x 2 tonight.
Don't have time to push my projects...


Daily. 832. Flipping an image

one-pass for loop is enough
Don't really understand the meaning of such questions...

No. 977 Squares of a sorted array

Kinda construct a merge sort case.
Find the min absolute value first, I can find that via binary search but I did not realize during coding.
One array is [min] - end and the other is [min] - start. Calculate the abs and choose which to add for each turn.
Process the remaining array items

No.540 Single Element in an array

Binary search.
The condition is to compare it to its "pair", pair is the following item if even, or previous item if odd.
If it is not the same, means the single item exists before index, otherwise after.
Compare current with prev and next to see if this is the item directly.

No.78 Subsets

Like permutation.
do it one by one.
For each newly coming item, we can add such item to all previous results, and just itself. This forms a new result for next item to use.

No.239 Sliding WIndow Maximum

I've written a slow result using priority_queue.
I've pushed value to a priority queue for the coming items.
For leaving items, I push to another priority queue, and
I pop the top of the second queue if it is equal to the first queue, aka the result for that window is changing. Keep doing this until not equal or the second queue is empty.
nlogn I think

Then I checked the discussion. Smart solution is using deque. Kinda they compare the lastly pushed value with the new item to ensure the queue is descending.
So the first item is the result for such sliding window.
Moreover, when an item leaves the window, check if it is top and remove if true.

Decent.

Keep fighting.
回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-12 16:38:16 | 只看该作者
全局:
Day 28. Daily Only. Pony ai has been processed to the maybe last interview (with manager...)
FB may provide STE (compared to FTE quq)



回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-13 15:25:06 | 只看该作者
全局:
Day 29. Daily only

回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-14 15:51:26 | 只看该作者
全局:
Day 30 Daily + high freq

Daily. populating next right

row scan. I've done much faster than last year haha

350. Intersection of Two Arrays

map solution is feasible for all kinds with T(n) = O(n)
considering if both are sorted. It is still O(n) actually.

257. Binary Tree paths

Very typical recursion (DFS)

207. Course Schedule

Topological sort
My solution is slow and I realized that instead of manipulating containers/vectors, adding if clause after reducing the indegree to see if such is a candidate for indegree=0 is better

622. Design circular queue

Record two pointers to know where is the start and where is the end. Instead, I use an end pointer and track the read size of the queue.

Keep fighting.
回复

使用道具 举报

🔗
 楼主| snowymo 2020-11-15 14:31:20 | 只看该作者
全局:
Why deleted my day 30???
Ridiculous

Daily 31


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表