📣 独立日限时特惠: VIP通行证立减$68
查看: 1169| 回复: 2
跳转到指定楼层
上一主题 下一主题
收起左侧

每日打卡刷题记录

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由 cherry19880908 于 2018-2-6 11:14 编辑

2/5/2018 开始刷题第一轮预计三个月
主要先完成Amazon,LinkedIn和Facebook标记的题,然后再看其他高频题,最后集中强化系统设计题。
每日打卡督促刷题



上一篇:开始刷题打卡
下一篇:18fall刷题打卡小组求战友
🔗
 楼主| cherry19880908 2018-2-6 11:00:26 | 只看该作者
全局:
2/5/2018
Amazon Questions 10题easy Array & String

1 Two Sum
HashMap<Integer, Integer>, (key: num, value: index)
if containsKey(nums[index]), get(nums[i])
else put (target - nums[index], index)
Time: O(n), Space: O(n)

20 Valid Parentheses
Stack<Character>
Time: O(n), Space: O(n)

242 Valid Anagram
use ASCII array as a hashmap, iterate through both strings, values in the array should be 0 at the end
Time: O(n), Space: O(1)

771 Jewels and Stones
Use ASCII array as a hashmap, A-65 to z-122
Time: O(n), Space: O(1)

189 Rotate Array
Split the array into two arrays at index k, reverse both arrays, combine and reverse the whole array
if(k>=len){
    k = k % len;
}
Time: O(n), Space: O(1)

387 First Unique Character in a String
Use ASCII array as a hash map, the value of the array is the count number of the character.
Time: O(n), Space: O(1)

167 Two Sum II - Input array is sorted
Use two pointers
Time: O(n), Space: O(1)

118 Pascal's Triangle
Use two List to store previous row and current row of the triangle
List<List<Integer>> result = new ArrayList<> ();
Time: O(k^2), Space: O(k^2)

119 Pascal's Triangle II
Use two array, Same as 118 Pascal's Triangle
Note: Could you optimize your algorithm to use only O(k) extra space?
1
11
121
1331
14641
Use only one array, add 1 at the end for each round, iterate through the array from right to left, add the previous two number row[j] =  row[j] + row[j-1]
Time: O(k^2), Space: O(k)

682. Baseball Game
Use an array to store the previous round’s point, use an index to keep track of current round
string to int: Integer.parseInt(ops[i]);
Time: O(n), Space: O(n)
回复

使用道具 举报

🔗
 楼主| cherry19880908 2018-2-7 14:44:04 | 只看该作者
全局:
2/5/2018
Amazon Questions 5题easy Linked List

206 Reverse Linked List
Use current, prev and next to reverse
while(current != null){
    next = current.next;
    current.next = prev;
    prev = current;
    current = next;
}
Time: O(n), Space: O(1)

21 Merge Two Sorted Lists
Create a extra node for the head of the merged list
Time: O(n), Space: O(1)

141 Linked List Cycle
Two pointers
while(fast != null && fast.next != null){
    slow = slow.next;
    fast = fast.next.next;
    if(fast == slow){
        return true;
    }
}
Time: O(n), Space: O(1)

234 Palindrome Linked List
Get the length of the linked list, split in half, reverse the second half, compare with the first to see if the lists are identical
Time: O(n), Space: O(1)

160 Intersection of Two Linked Lists
Solution 1: Get the length of both linked lists, if different, move the start pointer forward to the same length, check if the node are the same node
Solution 2: Iterate both linked lists, so the total length should be the same
For the end of first iteration, we just reset the pointer to the head of another linked list
For the second iteration, the pace is the same, as they are the same length and compare the node and find the intersection
If no intersection, after iterating both list and it will stop at null.
Time: O(n), Space: O(1)



回复

使用道具 举报

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

本版积分规则

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