Thursday, January 14, 2021

Upload File to S3

 require 'aws-sdk-s3'  # v2: require 'aws-sdk'


ACCESS_KEY_ID = ""

SECRET_ACCESS_KEY = ""

REGION_ID = "us-east-1"

BUCKET_NAME = "bucket-name"


def uploadS3

  credentials = Aws::Credentials.new(

                                     ACCESS_KEY_ID,

                                     SECRET_ACCESS_KEY

                                     )

  s3 = Aws::S3::Client.new(

                          region: REGION_ID,

                          credentials: credentials

                          )

                          

  #Upload export/file1.zip, export/file2.zip

  for file_name in ['file1.zip', 'file2.zip']

    name = File.join('export', file_name)


    # Upload

    File.open(name, 'rb') do |file|

      puts "start uploading #{file_name} to s3"

      resp = s3.put_object(bucket: BUCKET_NAME, acl: "public-read", key: file_name, body: file)

      puts resp

    end

    puts "File should be available at https://#{BUCKET_NAME}.s3.amazonaws.com/#{file_name}"

  end

end

Thursday, January 07, 2021

Law of Success

  1. Fall in love with the process.
  2. Do it every single day.
  3. Celebrate your commitment.
  4. Track your metrics and data.
  5. Master your craft.

Tommy Baker. “The 1% Rule: How to Fall in Love with the Process and Achieve Your Wildest Dreams.” 

Wednesday, January 06, 2021

Live Coding 175 Session Recordings Now Available

We have now over 175+ live coding recordings for Leetcode live coding sessions. That is over 200 hours of discussions on coding problems. We are a group of developers preparing for FANG interviews. We meet everyday and work collaboratively on solving one medium Leetcode problem via Zoom.

This is NOT a study group. We flip the classroom. You study whatever resources you find useful before the meeting. We only focus on PRACTICE and FEEDBACK during the Zoom calls. We share tips and the peer to peer learning has worked really well so far.

I started the daily live coding sessions on July 25th, 2020. I have learned in just two months as much as I have learned in one year when I was studying and practicing by myself. Members requested me to record the sessions so they can watch any sessions that they miss.

We don't rush into coding. We analyze the problem, create a model of the problem and use the model to answer questions. We then brainstorm alternate approaches to solve the problem starting with brute-force and eventually code the optimal solution by the end of the session.

This is not passive learning like watching videos. The paid courses ask you to pause the video and think. But no one teaches how to think and ask questions to solve problem from scratch. We code the solution to problems from scratch.

Our group hates memorizing and we focus on gaining deep understanding of the concepts. Join Leetcode Live Coding Telegram group: https://t.me/joinchat/VOy5LhxpFvgV4aJKeMBIRg

You will also get access to the Zoom cloud recordings. You will develop insights on how to approach coding problems and you don't have to memorize anything. You will learn how visualizing the key aspects of well known algorithms can make it easier to understand the algorithms at a deeper level. 

Tuesday, January 05, 2021

Topic Wise or Random Practice ?

 Topic wise practice if fine when you are learning the basics of data structures and algorithms. You basically can be operating in either Learning Mode or Practice Mode. When you are in learning mode, it's ok to practice by topic otherwise you should not be practicing by topic. Because, you have to develop the ability to recognize what data structure and algorithm to use just like a real interview.

Leetcode Live Coding Thread Discussion Link

 https://leetcode.com/discuss/general-discussion/1002477/Leetcode-Live-Coding

Thursday, December 31, 2020

Optimal Algorithm for a Problem

 “The ultimate goal in designing algorithms and data structures is to find an optimal algorithm for a problem, that is, an algorithm whose worst-case runtime complexity matches the intrinsic complexity of the problem it solves.”


Martin Erwig. “Once Upon an Algorithm: How Stories Explain Computing.” 

Problem Simplification

 “Problem simplification is often a crucial step toward solving a problem.”

Martin Erwig. “Once Upon an Algorithm: How Stories Explain Computing.” 

Relationship Between the Complexity of the Problem and Solution

 The distinction between the complexity of a problem and the complexity of its solutions helps us understand the notion of an optimal solution.


 Martin Erwig. “Once Upon an Algorithm: How Stories Explain Computing.” 

Precomputing

 In this case, even if the sorting takes linearithmic time, it is worth the effort, since it saves precious class time. This is an example of precomputing, where some data needed for an algorithm is computed before the algorithm is executed.

“This strategy of computing information ahead of time is called precomputation.”

“The crucial aspect of precomputation is that computational effort is expended at one time and the computed result is used at a later time. The precomputed result is preserved in a data structure”

“Situations in which one can expect to make use of a data structure repeatedly provide a strong incentive to expend the precomputing effort because the cost can be amortized over several uses.”

“ There are many situations, however, when it’s not clear whether the precomputation effort will pay off.”

“In cases like these, the value of acting early, or precomputing, is called into question by uncertainty about the future. Since the benefit of precomputation depends on a specific outcome of future events, it reflects a rather optimistic computation attitude with a confident outlook on the future.”

“A skeptical attitude toward the future calls for a radically different strategy for scheduling computation, namely, a strategy that tries to delay costly operations as much as possible until they cannot be avoided anymore. The hope or expectation is that something might happen that makes the costly operation obsolete and thus saves its runtime (and potentially other resources). In real life this behavior would be called procrastination; in computer science it is called lazy evaluation. ”

“Lazy evaluation can save computation effort whenever the information that would have been obtained by the saved computation is not needed anymore.”

“While lazy evaluation seems attractive in its promise to not waste effort, it is problematic when an action that becomes unavoidable takes longer than it would have under precomputing, or worse, longer than there is time available. In particular, when several delayed actions become due at the same time, this might present a serious resource problem. Therefore, an overall more sensible strategy is to distribute work evenly over time. While this might waste some effort on precomputing, it avoids crises that a lazy evaluation strategy might bring on.”

Martin Erwig. “Once Upon an Algorithm: How Stories Explain Computing.” 

Tuesday, December 29, 2020

Problem Sequence

 

  1. Contains Duplicate

  2. Missing Number

  3. Find All Numbers Disappeared in an Array

  4. Single Number

  5. Climbing Stairs

  6. House Robber

  7. Best Time to Buy and Sell Stock

  8. Maximum Subarray

  9. Range Sum Query - Immutable

  10. Linked List Cycle

  11. Middle of the Linked List

  12. Palindrome Linked List

  13. Remove Linked List Elements

  14. Remove Duplicates from Sorted List

  15. Reverse Linked List

  16. Merge Two Sorted Lists

  17. Meeting Rooms

  18. Binary Search

  19. Find Smallest Letter Greater Than Target

  20. Peak Index in a Mountain Array

  21. Binary Tree Level Order Traversal II

  22. Average of Levels in Binary Tree

  23. Minimum Depth of Binary Tree

  24. Same Tree

  25. Path Sum

  26. Diameter of Binary Tree

  27. Merge Two Binary Trees

  28. Maximum Depth of Binary Tree

  29. Lowest Common Ancestor of a Binary Search Tree

  30. Subtree of Another Tree

  31. Invert Binary Tree

  32. Two Sum

  33. Squares of a Sorted Array

  34. Backspace String Compare

  35. Longest Word in Dictionary

  36. Index Pairs of a String

  37. Majority Element

  38. Product of Array Except Self

  39. Find the Duplicate Number

  40. Find All Duplicates in an Array

  41. Set Matrix Zeroes

  42. Spiral Matrix

  43. Rotate Image

  44. Word Search

45. Letter Case Permutation 46. Subsets
47. Subsets II
48. Permutations

49. Permutations II
50. Combinations
51. Combination Sum
52. Combination Sum II 53. Combination Sum III 54. Generate Parentheses 55. Target Sum

56. Palindrome Partitioning
57. Letter Combinations of a Phone Number
58. Generalized Abbreviation
59. House Robber II
60. Coin Change
61. Maximum Product Subarray
62. Longest Increasing Subsequence
63. Longest Palindromic Substring
64. Word Break
65. Combination Sum IV
66. Decode Ways
67. Unique Paths
68. Jump Game
69. Palindromic Substrings
70. Number of Longest Increasing Subsequence
71. Partition Equal Subset Sum
72. Partition to K Equal Sum Subsets
73. Best Time to Buy and Sell Stock with Cooldown
74. Counting Bits
75. Linked List Cycle II
76. Add Two Numbers
77. Remove Nth Node From End Of List
78. Sort List
79. Reorder List
80. Clone Graph
81. Pacific Atlantic Water Flow
82. Number of Islands
83. Graph Valid Tree
84. Number of Connected Components in an Undirected Graph 85. Reverse Linked List II
86. Rotate List
87. Swap Nodes in Pairs
88. Odd Even Linked List

89. Kth Smallest Element in a Sorted Matrix 90. Find K Pairs with Smallest Sums
91. Merge Intervals
92. Interval List Intersections

93. Non-overlapping Intervals
94. Meeting Rooms II
95. Task Scheduler
96. Minimum Number of Arrows to Burst Balloons 97. Find Minimum in Rotated Sorted Array

98. Find Peak Element
99. Search in Rotated Sorted Array

  1. Search in Rotated Sorted Array II

  2. Search a 2D Matrix

  3. Search a 2D Matrix II

  4. Find K Closest Elements

  5. Minimum Size Subarray Sum

  6. Fruit Into Baskets

  7. Permutation in String

  8. Longest Repeating Character Replacement

  9. Kth Smallest Element in a BST

  10. K Closest Points to Origin

  11. Top K Frequent Elements

  12. Sort Characters By Frequency

  13. Kth Largest Element in an Array

  14. Reorganize String

  15. Course Schedule

  16. Course Schedule II

  17. Minimum Height Trees

  18. Binary Tree Level Order Traversal

  19. Binary Tree Zigzag Level Order Traversal

  20. Populating Next Right Pointers in Each Node

  21. Populating Next Right Pointers in Each Node II

  22. Binary Tree Right Side View

  23. All Nodes Distance K in Binary Tree

  24. Path Sum II

  25. Path Sum III

  26. Lowest Common Ancestor of a Binary Tree

  27. Maximum Binary Tree

  28. Maximum Width of Binary Tree

  29. Construct Binary Tree from Preorder and Inorder Traversal

  30. Validate Binary Search Tree

  31. Implement Trie (Prefix Tree)

  32. 3 Sum

  33. 3 Sum Closest

  1. Subarrays with Product Less than K

  2. Sort Colours

  3. Maximum XOR of Two Numbers in an Array

  4. First Missing Positive

  5. Longest Consecutive Sequence

  6. Sudoku Solver

  7. N-Queens

  8. Reverse Nodes in k-Group

  9. Merge k Sorted Lists

  10. Smallest Range Covering Elements from K Lists

  11. Insert Interval

  12. Employee Free Time

  13. Count of Range Sum

  14. Sliding Window Maximum

  15. Longest Substring Without Repeating Characters

  16. Minimum Number of K Consecutive Bit Flips

  17. Count Unique Characters of All Substrings of a Given String

  18. Minimum Window Substring

  19. Substring with Concatenation of All Words

  20. Rearrange String k Distance Apart

  21. Course Schedule III

  22. Maximum Frequency Stack

  23. Alien Dictionary

  24. Sequence Reconstruction

  25. Binary Tree Maximum Path Sum

  26. Serialize and Deserialize Binary Tree

  27. Word Search II

  28. Find Median from Data Stream

  29. Sliding Window Median

  30. Trapping Rain Water

  31. Container With Most Water

  32. Concatenated Words

  33. Prefix and Suffix Search

  34. Palindrome Pairs

  35. Design Search Autocomplete System

  36. Word Squares

  37. Sort Items by Groups Respecting Dependencies

  38. Median of Two Sorted Arrays