<?xml version="1.0" encoding="utf-8" ?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:tt="http://teletype.in/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"><title>Sherxon Developer</title><author><name>Sherxon Developer</name></author><id>https://teletype.in/atom/sheraliobidov</id><link rel="self" type="application/atom+xml" href="https://teletype.in/atom/sheraliobidov?offset=0"></link><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><link rel="next" type="application/rss+xml" href="https://teletype.in/atom/sheraliobidov?offset=10"></link><link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></link><updated>2026-05-13T22:05:40.506Z</updated><entry><id>sheraliobidov:SkkILlJsV</id><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov/SkkILlJsV?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><title>LinkedList Implementation and Basic Operations</title><published>2019-04-25T08:56:38.730Z</published><updated>2019-04-25T08:56:38.730Z</updated><summary type="html">&lt;img src=&quot;http://sherxon.com/assets/linked-list.png&quot;&gt;This is the first blog on linked lists that contains implementations in Java and introduces basic operation such as add, get and delete. You can also read about problems and their solutions on linked lists on LinkedList Common Problems and Solutions post.Linked List is a sequence of data that are connected by links. Each list item is commonly referred as Node. Every node stores certain data and a link to the next element. On the other hand, Linked lists can also have two links (previous and next) to optimize some operations. They are called doubly linked lists.Here is a simple illastration of singly linked lists.</summary><content type="html">
  &lt;p&gt;This is the first blog on linked lists that contains implementations in Java and introduces basic operation such as add, get and delete. You can also read about problems and their solutions on linked lists on &lt;a href=&quot;http://sherxon.com/blog/linked-list-2&quot; target=&quot;_blank&quot;&gt;LinkedList Common Problems and Solutions&lt;/a&gt; post.Linked List is a sequence of data that are connected by links. Each list item is commonly referred as Node. Every node stores certain data and a link to the next element. On the other hand, Linked lists can also have two links (previous and next) to optimize some operations. They are called doubly linked lists.Here is a simple illastration of singly linked lists.&lt;/p&gt;
  &lt;figure class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;http://sherxon.com/assets/linked-list.png&quot; width=&quot;605&quot; /&gt;
  &lt;/figure&gt;
  &lt;p&gt;and doubly linked list&lt;/p&gt;
  &lt;figure class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;http://sherxon.com/assets/doubly-linked-list.png&quot; width=&quot;604&quot; /&gt;
  &lt;/figure&gt;
  &lt;p&gt;Here is simple implementation of singly linked list in Java&lt;/p&gt;
  &lt;pre&gt;class LinkedList&amp;lt;E&amp;gt; {

    private Node head; // the first element
    private Node tail; // the last element
    int size;

    public void add(E element) {
        // tail and head are the same node when list has only one item
        if (head == null){
            head = tail = new Node(element);
        }else {
        //assign new node to next of tail and make tail the last element
            tail.next = new Node(element);
            tail = tail.next;
        }
        size++;
    }

    public E get(int index) {
        if (index &amp;gt;= size &amp;amp;&amp;amp; index &amp;lt; 0) // check boundaries
            throw new NoSuchElementException();

        // find element at given index
        Node node = head;
        for (int i = 0; i &amp;lt; index; i++)
            node = node.next;

        return node.elem;
    }

    public boolean delete(E element) {
        Node temp = new Node(null, head); // dummy element to avoid if checks
        Node dummy = temp;
        while (temp.next != null) {
            if (temp.next.elem.equals(element)) {
                // if found node is last node of the list, need to change tail
                if (temp.next == tail) tail = temp;
                temp.next = temp.next.next;
                // if found node is first node if the list, need to change head
                head = dummy.next;
                size--;
                return true;
            }
            temp = temp.next;
        }

        return false;
    }

    // wrapper class for list elements
    private class Node {
        E elem;
        Node next;
        public Node(E elem) {
            this.elem = elem;
        }
        public Node(E el, Node node) {
            this.elem = el;
            this.next = node;
        }
    }
  }
&lt;/pre&gt;
  &lt;p&gt;You can add addFirst and getFirst, addLast and getLast methods by changing references of head and tail respectively. They are easy and constant operations.And here is implementaion of doubly linked list. Every node stores element data and two links: prev and next.&lt;/p&gt;
  &lt;pre&gt;class DoublyLinkedList&amp;lt;E&amp;gt; {
    private Node head; // the first element
    private Node tail; // the last element
    int size;

    public void add(E element) {
        if (element == null) throw new AssertionError();

        // tail and head are the same node when list has only one item
        if (head == null) {
            head = tail = new Node(element);
        } else {
            //assign new node to next of tail and make tail the last element
            tail.next = new Node(element, tail, null);
            tail = tail.next;
        }
        size++;
    }
    public boolean isEmpty() {
         return size == 0;
    }
    public int getSize() {
         return size;
    }
    public E get(int index) {
        if (index &amp;gt;= size &amp;amp;&amp;amp; index &amp;lt; 0) // check boundaries
            throw new NoSuchElementException();

        // find element at given index
        Node node = head;
        for (int i = 0; i &amp;lt; index; i++)
             node = node.next;

        return node.elem;
    }

    public boolean delete(E element) {

        Node temp = head;
        while (temp != null &amp;amp;&amp;amp; !temp.elem.equals(element)) {
            temp = temp.next;
        }
        // no node with given element is found
        if (temp == null) return false;

        size--;

        // if found node is head of the list, need to change to next element
        if (temp == head) {
            head = head.next;
            return true;
        }
        // if found node is last node of the list, need to change tail
        if (temp == tail) {
            tail = temp.prev;
            return true;
        }
        // change links
        temp.prev.next = temp.next;
        temp.next.prev = temp.prev;

        return true;
    }

    // wrapper class for list elements
    private class Node {
        E elem;
        Node next;
        Node prev;

        public Node(E elem) {
             this.elem = elem;
        }
        public Node(E elem, Node prev, Node next) {
            this.elem = elem;
            this.next = next;
            this.prev = prev;
        }
    }
   }
&lt;/pre&gt;
  &lt;p&gt;This is the first blog about linked lists, you can read LinkedList Advanced Operations blog for recursion, reversing and some other operation imlementations.&lt;/p&gt;

</content></entry><entry><id>sheraliobidov:H11ODxA9E</id><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov/H11ODxA9E?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><title>LinkedList Common Problems and Solutions</title><published>2019-04-24T14:49:11.517Z</published><updated>2019-04-24T14:49:11.517Z</updated><summary type="html">This is my second blog on LinkedLists. In this blog, some of the most common problems and their solutions are discussed. You can also read about types of linked lists and implementations in Java in my prvious post, LinkedList Implementation and Basic Operations. To make a best use of this post, please read the question first and do little brainstorm before moving on to the solution. You can also try to implement solution once you are familiar with solution idea.1) Given a singly linked list, determine if it has a cycle in it.</summary><content type="html">
  &lt;blockquote&gt;This is my second blog on LinkedLists. In this blog, some of the most common problems and their solutions are discussed. You can also read about types of linked lists and implementations in Java in my prvious post, &lt;a href=&quot;http://sherxon.com/blog/linked-list&quot; target=&quot;_blank&quot;&gt;LinkedList Implementation and Basic Operations&lt;/a&gt;. To make a best use of this post, please read the question first and do little brainstorm before moving on to the solution. You can also try to implement solution once you are familiar with solution idea.1) Given a singly linked list, determine if it has a cycle in it.&lt;/blockquote&gt;
  &lt;p&gt;Solution:a) We iterate the list and add each element into the hashtable until current element is null or current element is already in the hashtable. This solution uses O(N) space to store list elements in hashtable. Time complexity is also O(N).b) We can use two pointers: &lt;strong&gt;slow&lt;/strong&gt; and &lt;strong&gt;fast&lt;/strong&gt;. &lt;strong&gt;slow&lt;/strong&gt; pointer moves step by step while &lt;strong&gt;fast&lt;/strong&gt; pointer moves two steps at a time. If the linked list has a cycle &lt;strong&gt;slow&lt;/strong&gt; and &lt;strong&gt;fast&lt;/strong&gt; pointers meet at some point. This solution uses O(1) space, which is better than previous solution.Here is implementation of solution in Java.&lt;/p&gt;
  &lt;pre&gt;boolean hasCycle(ListNode head) {
    if(head==null || head.next==null)return false;
    ListNode slow=head;
    ListNode fast=head.next;
    while(slow!=null &amp;amp;&amp;amp; fast!=null &amp;amp;&amp;amp; fast.next!=null){
        if(slow==fast)return true;
        slow=slow.next;
        fast=fast.next.next;
    }
    return false;
}
&lt;/pre&gt;
  &lt;blockquote&gt;2) Given two singly linked lists, find the node at which the intersection of these lists begins. Below given illustration of linked lists with intersection&lt;/blockquote&gt;
  &lt;pre&gt;A:          a1 → a2↘
                    c1 → c2 → c3
                    ↗
B:     b1 → b2 → b3
&lt;/pre&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;a) The easy solution is adding all elements of the first linked list into Hashset and checking one by one if an element of the second linked list is contained in the hashset.&lt;/p&gt;
  &lt;p&gt;Time Complexity is O(n+m) and Space Complecity is O(n)b) We iterate both lists and get length of each list. Then move pointer k steps forward on the longer list where k is the difference between lengths of lists. Now we need to move two pointers in both lists starting from head element in shorter list and kth element in longer list. We can find out intersection point the lists when two pointers meet at some point.&lt;/p&gt;
  &lt;p&gt;Time Complexity is O(max(m,n)) and Space Complecity is O(1)c) We maintain two pointers x and y at the head of A and B lists respectively. Then we move pointers one node at a time. When x reaches the end of a list, then redirect it to the head of B, similarly when y reaches the end of a list, redirect it the head of A. If at any point x meets y, then x/y is the intersection node.&lt;/p&gt;
  &lt;p&gt;Time Complexity is O(m+n) and Space Complecity is O(1)Below code snippet shows the third solution.&lt;/p&gt;
  &lt;pre&gt; ListNode getIntersectionNode(ListNode headA, ListNode headB) {
    if(headA==headB) return headA;
    ListNode x=headA;
    ListNode y=headB;
    while (x!=y){
        x= x==null ? headB : x.next;
        y= y==null ? headA : y.next;
    }
    return x;
}
&lt;/pre&gt;
  &lt;blockquote&gt;3) Given a linked list, return the node where the cycle begins without modifying the list. If there is no cycle, return null.&lt;/blockquote&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;a) We iterate the list and add every node into Hashset, if element is already in the set we can return this element as cycle starting point.&lt;/p&gt;
  &lt;p&gt;Time Complexity is O(n) and Space Complecity is O(n)b) This solution is combination of the first and the second problem solutions. We first find any point in the cycle if there is. Then break the list by setting next pointer of node to null and find intersection point of two lists. The intersection point is the point where cycle begins.&lt;/p&gt;
  &lt;blockquote&gt;Time Complexity is O(n+m) and Space Complecity is O(1)4) Reverse a singly linked list.&lt;/blockquote&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;a) We can reverse singly linked list in two ways, using recursion and iteration. The idea is to recur until tail node is encountered and set current node as next element of returned element in recursion.&lt;/p&gt;
  &lt;pre&gt;class Solution {
    ListNode newHead;
    public ListNode reverseList(ListNode head) {
        if(head == null || head.next == null)return head;
        reverse(head);
        head.next = null;
        return newHead;
    }
    ListNode reverse(ListNode current){
        if(current == null || current.next == null) {
            newHead = current;
            return current;
        }
        ListNode prev = reverse(current.next);
        prev.next = current;
        return current;
    }
}
&lt;/pre&gt;
  &lt;blockquote&gt;5) Sort a singly linked list in O(n log n) time using constant space complexity.&lt;/blockquote&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;We can use merge sort to sort linked list here. First we need to find mid element of the linked list using two pointers as mentioned above. Then, we should break the link by setting null to the next of mid element. In this case we can have have two lists; left linked list starts from head to mid and right linked list that starts from mid+1 to end of the linked list. We divide linked list until it has only one element in both left and right lists. Then starts merging of left and right lists into one sorted list. You can find solution below in Java&lt;/p&gt;
  &lt;pre&gt;public ListNode sortList(ListNode head) {
    if (head == null || head.next == null) return head;
    ListNode slow = head;
    ListNode fast = head.next;

    while (fast != null &amp;amp;&amp;amp; fast.next != null) { // slow in middle element
        slow = slow.next;
        fast = fast.next.next;
    }
    ListNode start2 = slow.next;
    slow.next = null; // break the link

    ListNode start1 = sortList(head); // sort first half
    ListNode start11 = sortList(start2); // sort second half

    return merge(start1, start11); // merge sorted arrays
}

ListNode merge(ListNode a, ListNode b) {
        ListNode root = new ListNode(0); // helper node
        ListNode x = root;
        while (a != null || b != null) {
            if (a == null) {
                x.next = b;
                b = b.next;
            } else if (b == null) {
                x.next = a;
                a = a.next;
            } else if (a.val &amp;lt;= b.val) {
                x.next = a;
                a = a.next;
            } else {
                x.next = b;
                b = b.next;
            }
        x = x.next;
      }
    return root.next;
}
&lt;/pre&gt;
  &lt;p&gt;These are some other commonly asked questions in interviews.&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/easy/RemoveDuplicatesLinkedList.java&quot; target=&quot;_blank&quot;&gt;Remove Duplicates from Sorted List&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/easy/PalindromeLinkedList.java&quot; target=&quot;_blank&quot;&gt;Palindrome Linked List&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/RotateList.java&quot; target=&quot;_blank&quot;&gt;Rotate List&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/AddTwoNumbers2.java&quot; target=&quot;_blank&quot;&gt;Add Two Numbers&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/MergekSortedLists.java&quot; target=&quot;_blank&quot;&gt;Merge k Sorted Lists&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;figure class=&quot;m_16x9&quot;&gt;
    &lt;iframe src=&quot;[object Object]&quot;&gt;&lt;/iframe&gt;
  &lt;/figure&gt;
  &lt;figure class=&quot;m_16x9&quot;&gt;
    &lt;iframe src=&quot;[object Object]&quot;&gt;&lt;/iframe&gt;
  &lt;/figure&gt;
  &lt;figure class=&quot;m_16x9&quot;&gt;
    &lt;iframe src=&quot;[object Object]&quot;&gt;&lt;/iframe&gt;
  &lt;/figure&gt;
  &lt;figure class=&quot;m_16x9&quot;&gt;
    &lt;iframe src=&quot;[object Object]&quot;&gt;&lt;/iframe&gt;
  &lt;/figure&gt;

</content></entry><entry><id>sheraliobidov:Hy2Mhj6qN</id><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov/Hy2Mhj6qN?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><title>Binary Tree Common Problems and Solutions</title><published>2019-04-24T09:27:48.371Z</published><updated>2019-04-24T09:27:48.371Z</updated><summary type="html">&lt;img src=&quot;http://sherxon.com/assets/bst.png&quot;&gt;In this post you can learn about binary tree common problems and their solutions in Java. You can also find interesting and elite problems solutions about Linked Lists in my previous post.</summary><content type="html">
  &lt;p&gt;In this post you can learn about binary tree common problems and their solutions in Java. You can also find interesting and elite problems solutions about Linked Lists in my &lt;a href=&quot;http://sherxon.com/blog/linked-list-2&quot; target=&quot;_blank&quot;&gt;previous post.&lt;/a&gt;&lt;/p&gt;
  &lt;h3&gt;Short Introduction to Binary Trees.&lt;/h3&gt;
  &lt;p&gt;Binary Trees are set of nodes in which one node is linked to two other nodes (left and right). Usually a reference or a pointer to topmost node is stored as a root, which can be used to traverse through all other nodes. In most cases Binary Trees are used as Binary Search Trees (BST) that have certain properties: the values in left sub tree is always smaller than or equal to its parent node&amp;#x27;s value and the values in right sub tree is always larger than its parent&amp;#x27;s value. Here is the illustration of BST.&lt;/p&gt;
  &lt;figure class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;http://sherxon.com/assets/bst.png&quot; width=&quot;759&quot; /&gt;
  &lt;/figure&gt;
  &lt;blockquote&gt;1)Given Binary Tree, print node values in pre-order, in-order, post-order and level order.&lt;/blockquote&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;Unlike linear data structures such as ArrayList, LinkedList, Queue and Stack, Binary Trees can be traversad in several ways. Main traversal methods of Binary Trees are&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Pre-order&lt;/strong&gt; - traversing starts from root and goes to left subtree then to right subtree&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;In-order&lt;/strong&gt; - traversing starts from left subtree and goes to root then to right subtree&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Post-order&lt;/strong&gt; - traversing starts from left subtree and goes to right subtree then to root&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Level-order&lt;/strong&gt; - traversing starts from root as level 1 and goes to every other level&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;Below are solution in Java for all 4 traversal methods.&lt;/p&gt;
  &lt;pre&gt;public void postOrder(TreeNode root) {
    if(root == null)return;
    postOrder(root.left); // first left
    postOrder(root.right); // and right
    System.out.print(root.val + &amp;quot; &amp;quot;); // then process
}

public void preOrder(TreeNode root) {
    if(root == null)return;
    System.out.print(root.val + &amp;quot; &amp;quot;); // process first
    preOrder(root.left); // go to left
    preOrder(root.right); // then right
}

public void inOrder(TreeNode root) {
    if(root == null)return;
    inOrder(root.left); // first left
    System.out.print(root.val + &amp;quot; &amp;quot;); // process
    inOrder(root.right); // then go to right
}

public void levelOrder(TreeNode root) {
    if (root == null) return;
    Queue&amp;lt;TreeNode&amp;gt; q = new LinkedList&amp;lt;&amp;gt;();
    q.add(root); // add first level to queue
    int nodeCountInLevel = 1;
        while (!q.isEmpty()) {
            TreeNode x = q.remove();
            nodeCountInLevel--;
            if (x.left != null)
                q.add(x.left);
            if (x.right != null)
                q.add(x.right);

            // move to next level when all nodes are processed in current level
            if (nodeCountInLevel == 0 &amp;amp;&amp;amp; !q.isEmpty()) {
                nodeCountInLevel += q.size();
                System.out.println(q);
            }
        }
}
&lt;/pre&gt;
  &lt;blockquote&gt;2) Invert Binary Tree&lt;/blockquote&gt;
  &lt;p&gt;Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off. &lt;a href=&quot;https://twitter.com/mxcl/status/608682016205344768&quot; target=&quot;_blank&quot;&gt;Here is motivation to learn how to invert Binary Tree.&lt;/a&gt;&lt;/p&gt;
  &lt;pre&gt;public TreeNode invertTree(TreeNode root) {
    if (root == null) return null;
    TreeNode tempRight = root.right;
    root.right = invertTree(root.left);
    root.left = invertTree(tempRight);
    return root;
}
&lt;/pre&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;The inverse of an empty tree is the empty tree. The inverse of a tree with root &lt;strong&gt;r&lt;/strong&gt; and subtrees &lt;strong&gt;left&lt;/strong&gt;b and &lt;strong&gt;right&lt;/strong&gt; is a tree with root &lt;strong&gt;r&lt;/strong&gt; whose right subtree is the inverse of &lt;strong&gt;left&lt;/strong&gt; and whose left subtree is the inverse of &lt;strong&gt;right&lt;/strong&gt;.&lt;/p&gt;
  &lt;pre&gt;public TreeNode invertTree(TreeNode root) {
    if (root == null) return null;
    TreeNode tempRight = root.right;
    root.right = invertTree(root.left);
    root.left = invertTree(tempRight);
    return root;
}
&lt;/pre&gt;
  &lt;p&gt;Time Complexity is O(n), becuase each node is vitised only once.&lt;/p&gt;
  &lt;p&gt;Space Complexity is O(n) because of recursion h (height) number of stack calls.&lt;/p&gt;
  &lt;blockquote&gt;3) Given two binary trees, check if they are structurally identical and the nodes have the same value.&lt;/blockquote&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;To invert a Binary Tree, we do pre-order traverse both trees and check if values of the nodes in each tree is the same. Iterative and recursive approach can be used to solve this problem. Below I presented my recursive solution.&lt;/p&gt;
  &lt;pre&gt;boolean isSameTree(TreeNode p, TreeNode q) {
        // base case
        if(p == null || q == null)return p ==q ;
        // recursion, check if values are equal
        return p.val == q.val &amp;amp;&amp;amp; isSameTree(p.left, q.left) &amp;amp;&amp;amp; isSameTree(p.right, q.right);
    }
}
&lt;/pre&gt;
  &lt;p&gt;Time Complexity is O(n), becuase each node is vitised only once.&lt;/p&gt;
  &lt;p&gt;Space Complexity is O(n) because of recursion h (height) number of stack calls.&lt;/p&gt;
  &lt;blockquote&gt;4) Find Lowest Common Ancestor (LCA) of a Binary Search Tree&lt;/blockquote&gt;
  &lt;p&gt;&lt;em&gt;According to &lt;a href=&quot;https://en.wikipedia.org/wiki/Lowest_common_ancestor&quot; target=&quot;_blank&quot;&gt;WikiPedia definition &lt;/a&gt;, The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself).&lt;/em&gt;&lt;/p&gt;
  &lt;pre&gt;public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
    if(root==null)return null;
    if(root.val &amp;lt; p.val &amp;amp;&amp;amp; root.val &amp;lt; q.val)
        return lowestCommonAncestor(root.right, p, q);
    else if(root.val &amp;gt; p.val &amp;amp;&amp;amp; root.val &amp;gt; q.val)
        return lowestCommonAncestor(root.left, p, q);
    else return root;
}
&lt;/pre&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;We walk down the tree as long as both p and q are in the same sub tree, in which case their values are both smaller than root&amp;#x27;s value or greater than root&amp;#x27;s value. Return when one of the p and q, are larger than root&amp;#x27;s value and the other is smaller than root&amp;#x27;s value.&lt;/p&gt;
  &lt;p&gt;Time Complexity is O(n), becuase each node is vitised only once.&lt;/p&gt;
  &lt;blockquote&gt;5) Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.&lt;/blockquote&gt;
  &lt;p&gt;Solution:&lt;/p&gt;
  &lt;p&gt;We subtract the value of current node from sum until it reaches a leaf node and the subtraction equals 0, then we can make sure there is a path. Otherwise the subtraction at the end could not be 0.&lt;/p&gt;
  &lt;pre&gt;public boolean hasPathSum(TreeNode root, int sum) {
    if(root == null)return false;
    sum-=root.val;
    if(sum == 0 &amp;amp;&amp;amp; root.left == null &amp;amp;&amp;amp; root.right == null) return true;
    return hasPathSum(root.left, sum) || hasPathSum(root.right, sum);
}
&lt;/pre&gt;
  &lt;h3&gt;Here are some other mostly encountered Binary Tree problems and Solutions&lt;/h3&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/easy/MaximumDepthofBinaryTree.java&quot; target=&quot;_blank&quot;&gt;Maximum Depth of Binary Tree&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/easy/MinimumDepthofBinaryTree.java&quot; target=&quot;_blank&quot;&gt;Minimum Depth of Binary Tree&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/ConvertSortedListtoBinarySearchTree.java&quot; target=&quot;_blank&quot;&gt;Convert Sorted List to Binary Search Tree&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/ConvertSortedArraytoBinarySearchTree.java&quot; target=&quot;_blank&quot;&gt;Convert Sorted Array to Binary Search Tree&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/easy/SymmetricTree.java&quot; target=&quot;_blank&quot;&gt;Check If Binary Trees are symmetric&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/FlattenBinaryTreetoLinkedList.java&quot; target=&quot;_blank&quot;&gt;Flatten Binary Tree to Linked List&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/BinaryTreeRightSideView.java&quot; target=&quot;_blank&quot;&gt;Binary Tree Right Side View&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/DeleteNodeinaBST.java&quot; target=&quot;_blank&quot;&gt;Delete Node in a BST&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/medium/ValidateBinarySearchTree.java&quot; target=&quot;_blank&quot;&gt;Validate Binary Search Tree&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;

</content></entry><entry><id>sheraliobidov:BJtNuphq4</id><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov/BJtNuphq4?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><title>File IO operation comparisons in Java</title><published>2019-04-23T17:15:29.235Z</published><updated>2019-04-23T17:15:29.235Z</updated><summary type="html">&lt;img src=&quot;https://teletype.in/files/88/88756379-80d1-4f7f-82a6-92c4b881a1bb.jpeg&quot;&gt;When I have free time, I attend contests in Online Judge websites just for fun. To get AC (passed all test cases and accepted) result in these contests, your solution has to be time and memory efficient. Most of the problems have several test cases to evaluate solutions. So, reading those test cases from file and outputting your results into another file to check may take much time as File Input and Output (IO) operations are toooo slow compared to other operations in most programming languages.I decided to benchmark all possible ways of reading and writing data into files in Java. Now I present you some results I found. Note that this post only shows results without any tuning disk file IO such as low level caching. Here are some...</summary><content type="html">
  &lt;p&gt;When I have free time, I attend contests in Online Judge websites just for fun. To get AC (passed all test cases and accepted) result in these contests, your solution has to be time and memory efficient. Most of the problems have several test cases to evaluate solutions. So, reading those test cases from file and outputting your results into another file to check may take much time as File Input and Output (IO) operations are toooo slow compared to other operations in most programming languages.I decided to benchmark all possible ways of reading and writing data into files in Java. Now I present you some results I found. Note that this post only shows results without any tuning disk file IO such as low level caching. Here are some approaches in Java with explanations you can use for writing into file and reading from it. These benchmarks are done using Intel® Core™ i3-3120M CPU @ 2.50GHz × 4 in 64-bit Ubuntu 14.04 with Java SE 1.8.0_20 on SSD. There are several factors(CPU, Hard disk and OS) that can make these benchmark results different. Hovewer, the relative difference is almost the same in all machines.&lt;/p&gt;
  &lt;figure class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://teletype.in/files/88/88756379-80d1-4f7f-82a6-92c4b881a1bb.jpeg&quot; width=&quot;738&quot; /&gt;
  &lt;/figure&gt;
  &lt;p&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/tree/master/src/oi&quot; target=&quot;_blank&quot;&gt;Link 1&lt;/a&gt; &lt;a href=&quot;https://github.com/sherxon/AlgoDS/tree/master/src/oi&quot; target=&quot;_blank&quot;&gt; Link 3&lt;/a&gt; &lt;a href=&quot;https://github.com/sherxon/AlgoDS/tree/master/src/oi&quot; target=&quot;_blank&quot;&gt;Link 5&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;https://github.com/sherxon/AlgoDS/tree/master/src/oi&quot; target=&quot;_blank&quot;&gt;Link 2&lt;/a&gt; &lt;a href=&quot;https://github.com/sherxon/AlgoDS/tree/master/src/oi&quot; target=&quot;_blank&quot;&gt;Link 4&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;What the Difference! You may be wondering why the famous and mostly used input stream approach is so slow. Main reason for this is that &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/io/FileInputStream.html&quot; target=&quot;_blank&quot;&gt;FileInputStream&lt;/a&gt; calls native read() method for each next 1 byte (raw octet, 8 bit) of the file content. When the file size is 1 MB, read() method is called 1048576 times that is 1024 x 1024. Now you can imagine how many times it is called for 1000MB. So, when working with Files, the first rule that you need to consider to speed up your application is the number of method calls() to underlying system and disk.&lt;strong&gt;Rule 1. Try to reduce number of method calls to underlying system and disk.&lt;/strong&gt;To reduce those method calls in FileInputStream, we can read some amount of data (1 MB or 2 MB) from disk and store it in memory then use this stored data. In this case, we dont make access to disk for each next byte. As accessing to memory is much faster than accessing to disk, we can speed up our reading operation. BufferedInputStream use the same strategy to make File IO faster by storing data in buffer (8192 bytes). When read() method is callled in BufferedStreams, data is read from buffered array in memory and rarely accesses to undelying system.We can create our own buffer array with bigger size and speed up reading. The Direct BufferedInputStream appraoch shows benchmark of using 2MB byte array as buffer. As you can see, that is nearly 10 times faster than Java&amp;#x27;s default Bufferedstream usage when it comes to read data from 1000 MB file. You can buffer the whole file into byte array as long as you have enough space in memory.&lt;strong&gt;Rule 2. Use your own buffer with certain size according to your business logic.&lt;/strong&gt;If you pay attention above, we only discussed about reading bytes from file. Hovewer, there are many cases that we want to read content of the file as characters. Unlike BufferedStreams, BufferedReader is all about reading characters. In the background, it reads bytes (like streams) from disk and translates into characters. You can see the BufferedReader works little slower than BufferedStreams because of translaton proccess.Next comes MemoryByteBuffer, which is Memory Mapped IO Class in Java. So, What is Memory Mapped file in Java? Memory mapped files are new feature in Java nio package, which allows to access contents of file directly from memory. This is achieved by mapping whole file or portion of file into memory and operating system takes care of loading page requested and writing into file while application only deals with memory which results in very fast IO operations. Memory used to load Memory mapped file is outside of Java heap Space. We use MappedByteBuffer in Java to read and write from memory.Memory Mapped files are so fast that they are used when performance is very important. However, there are some tradeoffs such as occurance of page faults if requested page is not in memory.If your application is dealing with small size of files, choosing MappedByteBuffer or BufferedStreams does not make much difference. Hovewer, reading data from large files using and changing certain pages of the file using multiple cores makes huge impact in performance. As Mapped Files loads the whole or some region of the file into shared memory, every process does not have to load the file into memory.&lt;/p&gt;

</content></entry><entry><id>sheraliobidov:SyNkYihcE</id><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov/SyNkYihcE?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><title>Microservice Architecture Pattern using Spring Boot and netflix technologies and helpful hints</title><published>2019-04-23T15:01:47.816Z</published><updated>2019-04-23T15:01:47.816Z</updated><summary type="html">This project can be used as showcase or Proof of Concept to build and manage micro services using Spring Boot.</summary><content type="html">
  &lt;p&gt;This project can be used as showcase or Proof of Concept to build and manage micro services using Spring Boot.&lt;/p&gt;
  &lt;p&gt;It includes:&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;https://github.com/sherxon/microservice-architecture/blob/master&quot; target=&quot;_blank&quot;&gt;Config Server&lt;/a&gt; =&amp;gt; Spring Cloud Config&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;https://github.com/sherxon/microservice-architecture/blob/master&quot; target=&quot;_blank&quot;&gt;API GateWay&lt;/a&gt; =&amp;gt; Zuul by Netflix&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;https://github.com/sherxon/microservice-architecture/blob/master&quot; target=&quot;_blank&quot;&gt;Service Registry&lt;/a&gt; =&amp;gt; Eureka by Netflix&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;https://github.com/sherxon/microservice-architecture/blob/master&quot; target=&quot;_blank&quot;&gt;Sample Spring Boot Application&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;If you are not familiar with micro service architecture pattern, I recommend 3 min reading &lt;a href=&quot;http://microservices.io/patterns/microservices.html&quot; target=&quot;_blank&quot;&gt;Microservice Architecture&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;first by Chris Richardson.&lt;/p&gt;
  &lt;h3&gt;General Overview&lt;/h3&gt;
  &lt;p&gt;All micro services are spring boot applications with dependencies managed by maven. Each Service has bootstrap.yml file which stores minimum required configuration for each service.&lt;/p&gt;
  &lt;p&gt;I have added all above mentioned micro services into one parent project just to make it easy to manage in one place&lt;/p&gt;
  &lt;p&gt;as it is just a POC project, without much business logic abd heavy requirements. You can still run each micro service independently.&lt;/p&gt;
  &lt;p&gt;This is &lt;a href=&quot;https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#config-first-bootstrap&quot; target=&quot;_blank&quot;&gt;Config First Bootstrap&lt;/a&gt;, so you should run Config Server first and Eureka Server second then Api Gateway and other micro services. You may see runtime exceptions thrown by Config Server when you run it until Eureka Server runs and Config server register itself.&lt;/p&gt;
  &lt;h3&gt;Helpful Hints&lt;/h3&gt;
  &lt;ul&gt;
    &lt;li&gt;Use &lt;code&gt;.yml&lt;/code&gt; files instead of &lt;code&gt;.properties&lt;/code&gt;, so you can write more than one profile configurations for each service with &lt;code&gt;---&lt;/code&gt;between them in one yml file and of course shorter code.&lt;/li&gt;
    &lt;li&gt;Keep all your source code always in certain package, not in source root to make it scanable by Spring DI&lt;/li&gt;
  &lt;/ul&gt;
  &lt;h3&gt;Config Server OverView&lt;/h3&gt;
  &lt;p&gt;Config Server is used to store configurations of all micro services in one centralized place. You can keep and change&lt;/p&gt;
  &lt;p&gt;configuration of any micro service such as database credentials and network location in externalized place and restart the service to pull new configuration. To learn more about it check this out &lt;a href=&quot;http://microservices.io/patterns/externalized-configuration.html&quot; target=&quot;_blank&quot;&gt;Externalized configuration&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;To implement externalized configuration pattern I used &lt;a href=&quot;https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html&quot; target=&quot;_blank&quot;&gt;Spring Cloud Config Server&lt;/a&gt; and config clients. To make any spring boot application a config server you can just add one maven starter dependency and &lt;code&gt;@EnableEurekaServer&lt;/code&gt; on configuration class. Spring cloud config server serves clients over rest api. Clients need to add spring-cloud-config-client dependency and config server or eureka server ( if you want config server to be discovered by eureka) location in bootstrap.yml&lt;/p&gt;
  &lt;p&gt;Once we run our config server at default 8888 port, we can get all configs using following rules in json format.&lt;/p&gt;
  &lt;p&gt;application is the name of service defined by &lt;code&gt;spring.application.name&lt;/code&gt; (or &lt;code&gt;spring.cloud.config.name&lt;/code&gt;) in config file.&lt;/p&gt;
  &lt;p&gt;profile is the name of profiles set by &lt;code&gt;spring.profiles.active&lt;/code&gt; on the client side , separated by comma&lt;/p&gt;
  &lt;p&gt;label is the label name to pull remote config files. if remote config location is git, the label is &lt;em&gt;master&lt;/em&gt; by default.&lt;/p&gt;
  &lt;p&gt;&lt;code&gt;/{application}/{profile}[/{label}]&lt;/code&gt; such as &lt;a href=&quot;http://localhost:8888/api-gateway/default&quot; target=&quot;_blank&quot;&gt;http://localhost:8888/api-gateway/default&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;&lt;code&gt;/{application}-{profile}.yml&lt;/code&gt;&lt;/p&gt;
  &lt;p&gt;&lt;code&gt;/{label}/{application}-{profile}.yml&lt;/code&gt;&lt;/p&gt;
  &lt;p&gt;&lt;code&gt;/{application}-{profile}.properties&lt;/code&gt;&lt;/p&gt;
  &lt;p&gt;&lt;code&gt;/{label}/{application}-{profile}.properties&lt;/code&gt;&lt;/p&gt;
  &lt;h3&gt;Attention&lt;/h3&gt;
  &lt;ol&gt;
    &lt;li&gt;If you want to store remote config in filesystem, besides providing file path: &lt;code&gt;spring.cloud.config.server.native.searchLocations=file:{path}&lt;/code&gt;, you should also use &lt;code&gt;spring.profiles.active=native&lt;/code&gt;profile.&lt;/li&gt;
    &lt;li&gt;You can just add &lt;code&gt;spring.cloud.config.server.bootstrap=true&lt;/code&gt; to bootstrap.yml of config server to tell config server to get its configuration from remote file or repository on git.&lt;/li&gt;
    &lt;li&gt;Use &lt;code&gt;@RefreshScope&lt;/code&gt; annotation in each client of config server, including config server itself, if you want changed configurations take an affect by sending post request &lt;code&gt;/refresh&lt;/code&gt; endpoints. from remote location.&lt;/li&gt;
    &lt;li&gt;Config Server does not cache configurations, it reads from remote location (git or filesystem) for each request.&lt;/li&gt;
  &lt;/ol&gt;
  &lt;h3&gt;Service Registry Overview:&lt;/h3&gt;
  &lt;p&gt;Service Registry is a service that keeps track of all other micro service instances, their location and health. All micro services register themselves with their information to Service Registry at startup and is deregistered if Service Registry cannot reach at certain point. Client Services such as Api Gateway ask Service Registry for location of available micro service instance. Eureka is used in this project as an implementation of Service Registry.&lt;/p&gt;
  &lt;h3&gt;Attention&lt;/h3&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;code&gt;@EnableEurekaClient&lt;/code&gt;==&lt;code&gt;@EnableDiscoveryClient&lt;/code&gt; makes spring boot app both instance (i.e. it registers itself and change &lt;code&gt;eureka.instance.*&lt;/code&gt;) and a client (i.e. it can query the registry to locate other services and change &lt;code&gt;eureka.client.*&lt;/code&gt; ).&lt;/li&gt;
    &lt;li&gt;if you want to enable &lt;code&gt;eureka.client.healthcheck.enabled=true&lt;/code&gt;, use application.properties for this config, otherwise you can see UNKNOWN status on Eureka dashboard.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;I dont have to write a lot about Eureka Server, you can read this awesome &lt;a href=&quot;http://blog.abhijitsarkar.org/technical/netflix-eureka/&quot; target=&quot;_blank&quot;&gt;Spring Cloud Netflix Eureka - The Hidden Manual&lt;/a&gt;blog by Abhijit Sarkar and get thorough understanding about Eureka Server.&lt;/p&gt;
  &lt;p&gt;In this project, Eureka server loads its configuration from Config Server and at the same time Config Server is eureka client.&lt;/p&gt;
  &lt;h3&gt;Api Gateway Overview&lt;/h3&gt;
  &lt;p&gt;Api Gateway (Zuul) is the implementation of Backend for Front-End pattern. Main motive to use Api Gateway is to have one edge service for clients and still manage a number of service instances and their locations (host+port) which change dynamically. To learn more about this, check this out &lt;a href=&quot;http://microservices.io/patterns/apigateway.html&quot; target=&quot;_blank&quot;&gt;Pattern: API Gateway&lt;/a&gt;&lt;/p&gt;
  &lt;h3&gt;Disclaimer&lt;/h3&gt;
  &lt;p&gt;This project is Shareware and distributed under GSL(General Sharewire Licence), which means you can do whatever you want with it once you share it with at least one person :). Most of ideas and &amp;quot;hints&amp;quot; are just my opinions and solutions to problems I have faced up. Thanks to stackoverflow and netflix community.&lt;/p&gt;
  &lt;p&gt;If you think improvement or a change is needed in any part of the project, feel to contribute !&lt;/p&gt;

</content></entry><entry><id>sheraliobidov:BJWdFt39V</id><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov/BJWdFt39V?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><title>How to write clean code</title><published>2019-04-23T12:47:36.530Z</published><updated>2019-04-23T12:47:36.530Z</updated><summary type="html">In this article, I am going to talk about a few key points on how to write clean code by avoiding some common mistakes. The term clean code is very broad and subjective, but there are conventions, standards and points to consider in coding that makes it more human readable.</summary><content type="html">
  &lt;p&gt;In this article, I am going to talk about a few key points on how to write clean code by avoiding some common mistakes. The term clean code is very broad and subjective, but there are conventions, standards and points to consider in coding that makes it more human readable.&lt;/p&gt;
  &lt;p&gt;Before starting talking about the key points to write clean code, I want to emphasize that It does not take one or two days to be good at clean coding. You need to practice until it becomes a second nature.&lt;/p&gt;
  &lt;p&gt;You are author and reader. While writing code, keep in mind that you are author and your target audience is not computer, it is you, your coworkers and millions of other developers in case it is open source. Writing every line of code with this idea in mind helps you use your knowledge to its fullest.&lt;/p&gt;
  &lt;p&gt;Let&amp;#x27;s start with very simple one-naming convention. Depending on your programming language choice, try to implement using only one (not mixed) naming convention across your team. Most popular ones are camelCase favoured by Java, C# community and snake_case which is popular among php and python programmers.&lt;/p&gt;
  &lt;p&gt;The next step on appropriate naming is that you should start paying attention to naming variables. The variable names should answer only one question with less word possible - &lt;strong&gt;what is the value of this variable to programmer.&lt;/strong&gt; It should never answer why this variable is created or how this variable is used. Here are couple of bad examples you have have seen.&lt;/p&gt;
  &lt;p&gt;As you read, variable names with single letter, unpronounceable words or generic names such as data and total are all very confusing when dealing with this variable. These types of naming leads to assumptions when reading it and assumptions create bugs. Sometimes, these bad naming comes from thinking too much about appropriate names eventually it loses its meaning.&lt;/p&gt;
  &lt;p&gt;When it comes to naming methods/functions, there is one simple rule. We know that a function does one job. Similarly, the function name should only answer to one question- &lt;strong&gt;What does this function do?&lt;/strong&gt;As you guess, it should have one verb and only tells about its purpose. If you create a function with nice name and the function does more than it suggests on its name, then you should reconsider renaming or moving extra logic into another function. The more atomic functions you have, the less arguments they will have as those functions do not need many arguments to do a single job. This makes code more beautiful and easy to reuse.&lt;/p&gt;
  &lt;p&gt;Next comes naming classes. You may think this is the easiest one because you usually have more options to name a class compared to variable. This is not always true. One of the biggest issues with class naming is long sentence-like names. Here are couple of examples&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;https://docs.spring.io/spring/docs/2.5.x/javadoc-api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html)%20https://docs.spring.io/spring/docs/2.5.x/javadoc-api/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.html&quot; target=&quot;_blank&quot;&gt;SimpleBeanFactoryAwareAspectInstanceFactory &lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;http://grepcode.com/file/repository.springsource.com/org.aspectj/com.springsource.org.aspectj.weaver/1.6.3/org/aspectj/weaver/patterns/HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor.java&quot; target=&quot;_blank&quot;&gt;HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;To avoid such names, you may try locating classes in right packages with concise documentation. Class names dont have to say anything about how/when/where to use. The only question class name should concern is what this class is about.&lt;/p&gt;
  &lt;p&gt;Habitual class naming such as ending exceptions with Exception keyword is another big issue among programmers. In most cases it completely makes sense to remove exception suffix from classes and the meaning does not change. &lt;em&gt;IllegalArgumentException&lt;/em&gt;, &lt;em&gt;NullReferenceException&lt;/em&gt; or &lt;em&gt;EntityNotFoundException&lt;/em&gt;are nice examples that can be used without the exception suffix. So, you may think about that not all big company libraries are appropriately named all the time.&lt;/p&gt;
  &lt;p&gt;White space is nice space. Often I see people writing smashed-up code without leaving any white space or line anywhere. This makes really hard to read and my eyes get strained while reading such code. If you’re implementing more logic in one block, and then try to separate the code chunks into logical pieces with a white line break. Maybe have all of your code that use data fetching from database, then a line of whitespace, and then write another chunk where you do process them. Things like this might seem annoying at the time of writing, but are crucial when trying to quickly find something in a large section of unfamiliar code.&lt;/p&gt;
  &lt;p&gt;Commenting, it saves time for programmer and money for company. The easiest way of contributing to project success is by commenting existing code. Sometimes, it seems daunting to write couple lines of comments after implementing performant algorithm or solving huge problem. But the commenting this adds more value to the solution.&lt;/p&gt;
  &lt;p&gt;Here are some ways that can help you to make habit of writing clean code. You can always download nice coding style &lt;a href=&quot;https://google.github.io/styleguide/&quot; target=&quot;_blank&quot;&gt;Google coding style guide&lt;/a&gt; and integrate it your powerful IDE. This makes sure that you have right naming convention and indentation to some extend.&lt;/p&gt;
  &lt;p&gt;Happy clean coding!&lt;/p&gt;

</content></entry><entry><id>sheraliobidov:BytpeFh9E</id><link rel="alternate" type="text/html" href="https://teletype.in/@sheraliobidov/BytpeFh9E?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=sheraliobidov"></link><title>Google ga software engineer bo'lib ishga kirish haqida</title><published>2019-04-23T12:10:40.955Z</published><updated>2019-04-23T12:10:40.955Z</updated><summary type="html">Google ga qanday qilib kelib qoldim :)</summary><content type="html">
  &lt;p&gt;Google ga qanday qilib kelib qoldim :)&lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;Bu blogimda doimgi mavzulardan tashqariga chiqib, qanday qilib, Google ga software engineer bo&amp;#x27;lib, ishga kirganim haqida yozmoqchiman. Interview process haqida o&amp;#x27;zbek tilida (bilmagan joylarimni ingliz tilada :) yozib, to&amp;#x27;liq ma&amp;#x27;lumot berishim, O&amp;#x27;zbekistonlik va boshqa o&amp;#x27;zbek tili so&amp;#x27;zlovchilariga ozgina bo&amp;#x27;lsa-da, motivatsiya bo&amp;#x27;lishiga umid qilaman. Iloji boricha, detailed yozishga harakat qilaman va agar yana savollaringiz bo&amp;#x27;lsa, bemalol yozib qoldirishingiz mumkin. Imkoni boricha, javob berishga harakat qilaman.&lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;Bundan 3-4 yil avval dasturchi do&amp;#x27;stlarim bilan qat&amp;#x27;iy qaror qildik: o&amp;#x27;z sohamizning yuqori cho&amp;#x27;qqisiga chiqamiz! Maqsadga erishishdagi rejalarimiz ichida eng yaxshi dasturchilar ishlaydigan kompaniyalardan biriga ishga kirish va u yerdagi tajribali insonlar bilan birga ishlab, yanada rivojlanish ham bor edi.&lt;/p&gt;
  &lt;p&gt;Shu niyatlar bilan 2016-yil Toshkentdagi Xalqaro Westminster Universitetida bakalavrni bitirib, shu yilning kuzida Amerikada magistratura o&amp;#x27;qish uchun Iowa shtatidagi Maharishi Management Universitetiga o&amp;#x27;qishga keldim. U yerda 1 yil universitet campusda full time o&amp;#x27;qidim. Ikkinchi yilni online o&amp;#x27;qish imkoniyati borligidan foydalanib, Chicagodagi bir kichikroq kompaniyada software engineer sifatida ish boshladim. Maharishi Universiteti ishga kirish uchun juda katta yordam berdi: kuchli o&amp;#x27;qitiladigan fanlardan tashqari, Amerikada ishga kirish jarayonlarini tushuntirib, ish ruhsatnomasini ham qilib berdi.&lt;/p&gt;
  &lt;p&gt;Online o&amp;#x27;qib yurgan paytlarimda ishlaganim uchun, o&amp;#x27;qish pulini to&amp;#x27;lash unchalik qiyin bo&amp;#x27;lmadi. Ma&amp;#x27;lumot uchun, masterga tuition fee 40,000$ atrofida ketdi.&lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;Interview preparation&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;Masterning birinchi yilida campus da o&amp;#x27;qib yurgan vaqtimda, asosan algorithm/data structure va system design ga oid mavzular o&amp;#x27;rgandim/masalalar yechib practice qildim. Bunda Cracking the coding interview by McDowell, Algorithm design manual by Skiena va Algorithms By Sedgwick katta yordam berdi. Leetcode va hackerrank/timus dan similar problems yechib, kitoblardan o&amp;#x27;rgangan theoriyalar ustida shug&amp;#x27;ullandim. Interview da o&amp;#x27;zimni qanday tutishni esa Pramp da mock intervyular qilib o&amp;#x27;rgandim.&lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;Interview process&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;Google da interview process boshqa katta tech company larnikidan farq qiladi va o&amp;#x27;rtacha 3-6 oy vaqt oladi. Men o&amp;#x27;zimda bo&amp;#x27;lgan process haqida yozaman. Qaysi level/position ga apply qilinganiga qarab, ba&amp;#x27;zida bundan sal farqli bo&amp;#x27;lishi mumkin.&lt;/p&gt;
  &lt;p&gt;Birinchi step interview da, recruiter email yoki linkedin profilga message yozadi va open position borligi haqida ma&amp;#x27;lumot berish uchun telda gaplashishga vaqtingiz borligini so&amp;#x27;raydi. Online application topshirganlarga ham xuddi shunaqa steps bo&amp;#x27;ladi. Kelishilgan vaqtda telda gaplashib, qiziqish bor-yo&amp;#x27;qligini va qachon ish boshlay olishingiz mumkinligini so&amp;#x27;raydi. Shundan keyin, candidate qiziqishiga qarab, ikkinchi stepga o&amp;#x27;tiladi. Ya&amp;#x27;ni online/phone screening technical interview. O&amp;#x27;rtacha 45 min bo&amp;#x27;ladi. Video yoki audio chat qilib, Google dagi biror software engineer bilan har xil coding problemalar yechiladi. Mening holatimda 45 minut faqat technical savollar bo&amp;#x27;ldi. Behavioral savollar deyarli so&amp;#x27;rashmaydi. 2-3 ta masala beriladi and/or common algorithms and data structure concept larni tushuntirib berishingiz so&amp;#x27;ralishi mumkin.&lt;/p&gt;
  &lt;p&gt;Bundan successful o&amp;#x27;tilgandan keyin, interviewer feedback iga qarab, yana boshqa screening interview bo&amp;#x27;lishi mumkin yoki directly onsite interview ga chaqirilishi mumkin. Men bilan interview feedback yaxshi bo&amp;#x27;lgani uchun, to&amp;#x27;g&amp;#x27;ri onsite ga kelishni taklif qilishdi. Meni vaqtimga qarab, airplane tickets va inteview joyiga yaqin mehmonxonadan xona band qilishdi. Bir kun oldin kelib, mountain view ga, ertasiga ertalab soat 10 da inteview uchun yetib bordim va har biri 45 daqiqalik 5 round technical interview bo&amp;#x27;ldi.&lt;/p&gt;
  &lt;p&gt;Uchinchi round interviewdan keyin orada tushlik uchun 1 soat ajratishadi. Interview dagi aniq savollarni confidential bulgani uchun yozolmayman, lekin mavzular: algorithms, data structures, system design doirasida bo&amp;#x27;ldi. O&amp;#x27;rganishni maslahat berishim mumkin bo&amp;#x27;lgan mavzular all common data structures and algorithms:stack, queue, heap, list, hashtables, trees and graphs; sorting and searching algos, graph and tree traversals and common related problems, little bit knowledge of dynamic programming and bit manipulation. Tepada eslatgan kitoblarimni o&amp;#x27;qib, tushunilsa, bemalol yetarli bo&amp;#x27;ladi va faqat qolgani practice bilan interview ga kelsa bo&amp;#x27;ladi. System design uchun aniq bir kitob hozircha maslahat berolmayman. Chunki men o&amp;#x27;zim, asosan, online da article lardan va bloglardan o&amp;#x27;qib o&amp;#x27;rganganman. Qiziqqanlar contact qilsa, system design uchun resource larimni yuboraman.&lt;/p&gt;
  &lt;p&gt;Onsite interview dan keyin, recruiter 1-2 haftada aniq javobni aytish uchun tel qiladi va benefits/compensation/relocation packages haqida deal qilinadi. Va undan keyin team matching boshlanadi: Google da resumeyingizni o&amp;#x27;qib, sizni o&amp;#x27;z komandasiga olishga qiziqqan team manager lar bog&amp;#x27;lanib, ular bilan ishlashga fikringizni so&amp;#x27;rashadi. Bu step da candidate o&amp;#x27;zi uchun qiziq bo&amp;#x27;lgan savollar so&amp;#x27;raydi: komanda haqida, nima ish qilishi, project development process va career growth opportunities haqida.&lt;/p&gt;
  &lt;p&gt;Aniq sizga yoqadigan team va project/product topilgandan keyin, recruiter 1 haftalarda official job offer yuboradi va background check boshlanadi. Bu stepda resumeyingizda ko&amp;#x27;rsatilgan experience va education lar haqiqiy ekanligini tasdiqlash uchun ularga bog&amp;#x27;lanib, confirmation olishadi.&lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;Impression working here so far&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;Birinchi 3 hafta training dan keyin komandada haqiqiy ish boshlandi. Trainingda Google dagi muhitni va ishlatiladigan tool lar bilan tanishtirishdi. Boshlaganimga endigina 2 oy bo&amp;#x27;lgan bo&amp;#x27;lsa ham, juda ko&amp;#x27;p narsa o&amp;#x27;rgandim. Eng muhimi, o&amp;#x27;rganish va o&amp;#x27;rganganlaringizni amalda qo&amp;#x27;llash uchun barcha imkoniyatlar yetarli.&lt;/p&gt;
  &lt;p&gt;Google ishchilar haqida juda care qiladi: 3 mahal ovqat, entertainment, gym/pool resources, flexible work life balance, great benefits package, yaxshigina oylik ham beradi. To&amp;#x27;g&amp;#x27;risini aytsam, perks ko&amp;#x27;pligidan hali hammasini try qilib ko&amp;#x27;rmadim.)&lt;/p&gt;
  &lt;p&gt;Engineerlar juda professional va tajribali. Manager larning ko&amp;#x27;pchiligi engineer likdan boshlashgan va o&amp;#x27;zlarini hali ham engineer deb bilishadi. Solution topishga va product delivery qilishga nisbatan ham boshqa companylarga qaraganda ancha farqli usullardan foydalanishadi. Yana bir-ikki yildan keyin, Google haqida ko&amp;#x27;proq yoza oladigan bo&amp;#x27;lganimda boshqa postda batafsil yozaman.&lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;That&amp;#x27;s is it for now.&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;O&amp;#x27;zimda juda ko&amp;#x27;p &amp;quot;qanday qilib&amp;quot; degan savollar bo&amp;#x27;lardi. Savollar bo&amp;#x27;lsa, istalgan vaqt facebookda contact qilinglar. Imkoni boricha javob beraman, Xudo xohlasa)&lt;/p&gt;
  &lt;p&gt;PS. No judging on typos.&lt;/p&gt;

</content></entry></feed>