Over the last few years I have applied and interviewed at a number of tech firms such as Google, Yelp, Microsoft, Amazon, Adobe and other big names. I have received offers from Palantir, Workday, Flixbus, etc. In order to be successful during those interviews (but also as an engineer in . . . Read more
Problem statement Given a linked list, determine if it has a cycle in it. Solution For the solution we are going to use a technique known as the twopointer technique. That is we will involve two pointers: one slowrunner and the other fastrunner. The slowrunner will move forward 1 list . . . Read more
If you get this error while uploading a new theme, your web server is rejecting the upload due to the overall size of the file. WordPress is unfortunately giving you a rather ambiguous message in response. This is not a theme issue or bug. In order to increase your PHP . . . Read more
In this post I have described how to manually renew Let’s Encrypt SSL certificate. Here I describe how to configure a cronjob to automatically renew my certificates when they are about to expire. Setup default AMI editor to nano:
Add the following:

17 */12 * * * mv /var/www/html/.htaccess /var/www/html/.htaccess_ && /usr/local/letsencrypt/letsencryptauto certonly webroot w /var/www/html d lucaslouca.com d www.lucaslouca.com config /etc/letsencrypt/config.ini agreeto quiet && mv /var/www/html/.htaccess_ /var/www/html/.htaccess && rm rf /var/www/html/.wellknown/ 
The && operator makes sure . . . Read more
Problem statement Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. Solution Obviously the naive approach to this problem would be to subtract the divisor from the dividend until the dividend becomes less than the divisor, while keeping track of how many times . . . Read more
Problem statement Given a list, nums, of distinct numbers, return all possible unique permutations. Sample input
Sample output

[[1, 2, 1], [2, 1, 1], [1, 1, 2]] 
Solution In another post we showed how this problem can be solved iteratively. We can use the same technique but add a check to skip adding the number n to . . . Read more
Problem statement Given a list, nums, of distinct numbers, return all possible permutations. Sample input
Sample output

[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] 
Solution In another post we showed how this problem can be solved using a recursive technique by swapping. We stumbled upon a nice iterative solution that we thought might be worth . . . Read more
Problem statement Given a list, nums, of distinct numbers, return all possible permutations. Sample input
Sample output

[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] 
Solution We are using a technique called permutations by swapping. Full code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

class Solution(object): def swap(self, nums, i, j): tmp = nums[i] nums[i] = nums[j] nums[j] = tmp def solve(self, nums, i, result): if i == len(nums)1: result.append(list(nums)) return for j in range(i, len(nums)): self.swap(nums, i, j) self.solve(nums, i+1, result) self.swap(nums, i, j) def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ ans = [] self.solve(nums, 0, ans) return ans def main(): solution = Solution() print(solution.permute([1,2,3])) if __name__ == "__main__": main() 
Problem statement You are given an 2D matrix / array representing an image. Rotate matrix by 90 degrees (clockwise) inplace. Solution We will work through the matrix layers. The layers of a matrix are illustrated below in different colours: There are a total of layers. We then iterate of the . . . Read more
Problem statement A time series is a series of data points indexed in time order. They are commonly used in the financial world, especially in stock markets. In this challenge you are working with a time series of stock prices. You are given historical records where the stock at time . . . Read more