System Design Tools and Templates

  1. Tools

Draw.io

Visual paradigm

Lucid chart

2. Templates

Problem Statement

Scope

Design Goals

Assumptions

High Level Design

Challenges

Open Items

References

Posted in system design | Comments Off on System Design Tools and Templates

Interview Resources

Pramp

BigOCheatSheet

Hackerrank

Interviewing.io

Grokking the system design interview

Cracking the coding interview

Leetcode

Posted in resources | Comments Off on Interview Resources

common git problems

Delete the remote branch

git push -d origin <branch_name>

Delete the local branch

git branch -D <branch_name>

Merge master into feature branch

git checkout master

git pull

git checkout feature

git merge master

Checkout from a specific commit

Use git checkout <sha1> to check out a particular commit

git checkout -b <branch> <commit>

Revert commit

git revert <commit_hash>

git revert <oldest_commit_hash>..<latest_commit_hash>

Setting your branch to exactly match the remote branch can be done in two steps:

git fetch origin

git reset –hard origin/master

Remove a file from PR

git checkout origin/master — src/main/java/HelloWorld.java

git commit -m “Removed files from PR”

Sync your fork with original

# Add a new remote upstream repository

git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

# Sync your fork

git fetch upstream

git checkout master

git merge upstream/master

git remote add upstream <>

If you need to remove a single file from the staging area, use

git reset HEAD — <file>

Remove submodule dirty

git submodule foreach –recursive git checkout .

git submodule update –force –recursive –init –remote

Posted in git | Comments Off on common git problems

longest-substring-without-duplicate-characters

public class LengthOfLongestSubstring {
public static int lengthOfLongestSubstring(String s) {
if (s == null) {
return 0;
}
Map<Character, Integer> map = new HashMap<>();
int maxLength = 0;
int start = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
Integer duplicateIndex = map.put(c, i);
if (duplicateIndex != null) {
if (duplicateIndex >= start) {
maxLength = Math.max(maxLength, i - start);
start = duplicateIndex + 1;
}
}
}
return Math.max(maxLength, s.length() - start);
}

public static void main(String[] args) {
int maxLength = lengthOfLongestSubstring("abcabcbb"); // 3
System.out.println(maxLength);

maxLength = lengthOfLongestSubstring("bbbbb"); // 1
System.out.println(maxLength);

maxLength = lengthOfLongestSubstring("b"); // 1
System.out.println(maxLength);

maxLength = lengthOfLongestSubstring(""); // 0
System.out.println(maxLength);

maxLength = lengthOfLongestSubstring(null); // 0
System.out.println(maxLength);
}
}
Posted in hashtable | Comments Off on longest-substring-without-duplicate-characters

sorted-square

public class SortedSquare {
public static int[] sortedSquare(int[] nums) {
int[] result = new int[nums.length];
int writeIndex = nums.length - 1;
int l = 0, r = nums.length - 1;
while (l <= r) {
if (nums[l] * nums[l] < nums[r] * nums[r]) {
result[writeIndex] = nums[r] * nums[r];
r--;
} else {
result[writeIndex] = nums[l] * nums[l];
l++;
}
writeIndex--;
}
return result;
}

public static void main(String[] args) {
Utils.printArray(sortedSquare(new int[]{-4, -2, -1, 0, 1, 3, 5}));

}
}
Posted in sorting | Comments Off on sorted-square

sum-of-left-leaves

package us.inest.app.dcp.recursion;

import us.inest.app.dcp.tree.TreeNode;

public class SumOfLeftLeaves {

public static int sumOfLeftLeaves(TreeNode root) {

// base case

if (root == null) {

return 0;

}

// left child is a leaf node

if (root.left != null && root.left.left == null && root.left.right == null) {

return root.left.data + sumOfLeftLeaves(root.right);

}

return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);

}

}

Posted in recursion | Comments Off on sum-of-left-leaves

remove-nth-node-from-end-of-list

LeetCode link: https://leetcode.com/problems/remove-nth-node-from-end-of-list/submissions/684704570/

Java Solution

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode first = head;
        
        //null list
        if (head == null) {
            return head;
        }
        
        for (int i = 0; i < n; i++) {
            if (first.next == null) {
                return (i == n - 1) ? head.next : head;
            }
            first = first.next;
        }
        ListNode second = head;
        while (first.next != null) {
            first = first.next;
            second = second.next;
        }
        
        second.next = second.next.next;
        return head;
    }
}
Posted in singly-linked list | Comments Off on remove-nth-node-from-end-of-list