LeetCode - Reorder Data in Log Files

You have an array of logs.  Each log is a space delimited string of words.
For each log, the first word in each log is an alphanumeric identifier.  Then, either:
  • Each word after the identifier will consist only of lowercase letters, or;
  • Each word after the identifier will consist only of digits.
We will call these two varieties of logs letter-logs and digit-logs.  It is guaranteed that each log has at least one word after its identifier.
Reorder the logs so that all of the letter-logs come before any digit-log.  The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties.  The digit-logs should be put in their original order.
Return the final order of the logs.

Example 1:
Input: logs = ["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]
Output: ["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]

Constraints:
  1. 0 <= logs.length <= 100
  2. 3 <= logs[i].length <= 100
  3. logs[i] is guaranteed to have an identifier, and a word after the identifier.

Solution :

Java Solution :



class Solution {
    public String[] reorderLogFiles(String[] logs) {
        Arrays.sort(logs,(log1,log2)->{
            String[] set1 = log1.split(" ",2);
            String[] set2 = log2.split(" ",2);
            boolean isCharacter1 = Character.isLetter(set1[1].charAt(0));
            boolean isCharacter2 = Character.isLetter(set2[1].charAt(0));
            if(isCharacter1 && isCharacter2){
                int cmp = set1[1].compareTo(set2[1]);
                if(cmp !=0) return cmp;
                return set1[0].compareTo(set2[0]);
            }
            return !isCharacter1 ? (!isCharacter2 ? 0 : 1) : -1;
        });
        return logs;
    }
}

Amazon Onsite Interview Questions

1.  Two Sum
2. Most Common Word
3. Reorder Log files
4.Trapping Rain Water
5.Copy List With Random Pointer
6.Number of Islands
7. Lowest common ancestor of Binary tree
8.Binary Tree Zig zag level order traversal
9. Word Ladder 1 , 2
10. word search 1  , 2
11. Meetings rooms 1 , 2
12. Kth largest element in array.
13. K closest points to Origin.
14.Longest Palindromic Substring.
15. LRC Cache
16. Tic Toc Toe
17. Leetcode all design questions.
18. Prison cells after N days.
19. word break 2
20.  stream of characters (DNA Sequence )
21.
Given a 2d array in which each row is sorted and rotated, you need to come up with an algorithm which efficiently sort the entire 2d matrix in descenting order.
eg:
input: arr[][] = {
{41, 45, 20, 21},
{1 ,2, 3, 4},
{30, 42, 43, 29 },
{16, 17, 19, 10}
}
output: {
{ 45, 43, 42, 41},
{30, 29, 21, 20},
{19, 17, 16, 10},
{4, 3, 2, 1}
}
Interviewer was expecting the solution to run with a complexity < O(n^3) solution.


23. https://leetcode.com/problems/top-k-frequent-elements/

nput is in <productId, timeStamp> format. So assume you have a list of productIDs and their timestamps which they were accessed:
[<product1, timestamp1>, <product2, timestamp2>, <product3, timestamp3>, ...]
Find the top K products purchased in the last one hour.

24. We have two Queues where each queue contains timestamp price pair. We have to return list of list[[price1, price 2]] for all those timestamps where abs(ts1-ts2) <= 1 second where ts1 and price1 are the from the first queue and ts2 and price2 are from the second queue.
Follow up:- one queue is slow

25.Deep copy of an N-ary tree.

public TreeNode clone(TreeNode root) {
  if (root == null) {
    return null;
  }

  TreeNode rootClone = new TreeNode(root.val);
  for (TreeNode child : root.children) {
    TreeNode childClone = clone(child);
    rootClone.children.add(childClone);
  }

  return rootClone;
}

private static class TreeNode {

  int val;
  List<TreeNode> children = new ArrayList<>();

  public TreeNode() {
  }

  public TreeNode(int val) {
    this.val = val;
  }
}
26.https://leetcode.com/problems/subsets/
Now the follow-up question is to remove that for loop from backtrack funtion and pass the indexes. I tried to keep i index by passing it to the function by couldn't figure out the index incrementing logic.
ay we have a machine which scans a printed word and assigns a probablity to each character of the word. For example, if we scan LBC, the machine produces the following map for the word (first list will be for the first char, second list for the second char etc.) :
{
 ['L': 90, 'I': 50, 'N': 10],      // for first character (L)
 ['B': 95, '8': 80, 'S': 15],      // for secodn character (B)
 ['C': 90, 'O': 90, 'D': 70]       // for third character (C)
}
Meaning for the first character there is a 90 percent chance that it is L, 50 percent that it is I etc. Given a list of Strings, return the word with the highest probablity based on this map. For example, if the list is {LBD, IBC, LSD}LBD should be returned (with the probablity of 90 + 95 + 70).
27. Consider that there are 26 tables, listed from A to Z. Each table is connected with table next to it. A connected to B, B to C so forth and so on till Z.
How will you connect table A and Z with minimum number of joins?
There are two anagram strings, what is the minimum number of swaps required to match one string to another? You can swap any 2 characters. What is time complexity?
Example 1:
Input: s1 = "AABC", s2 = "AACB"
Output: 1
Explanation: swap 'B' and 'C' AABC => AACB
29.Position: SDE2
Design a configuration management system
  • User should be able to add configuration
  • User should be able to delete configuration
  • User should be able to search for configuration
  • User should be able to subscribe to Configuration So that any updates in configuration will gets notfied to user
30.I have my amazon interview coming up for SDE in seattle. One of my friends recently went on-site in Seattle and was asked this question in OOD. I have not been able to find a good approach to this question. Any suggestions would be helpful
implemnet linux find command as an api ,the api willl support finding files that has given size requirements and a file with a certain format like
  1. find all file >5mb
  2. find all xml Assume file class { get name() directorylistfile() getFile() create a library flexible that is flexible Design clases,interfaces.
31. https://leetcode.com/problems/analyze-user-website-visit-pattern
32. Given an array of strings, you need to group isomorphic strings together.
Example:
Input: ["apple", "apply", "dog", "cog", "romi"]
Output: [["dog", "cog"], ["romi"], ["apple", "apply"]]
33. Load Packages

Algorithm Run Time Analysis

Algorithm Run Time Analysis:


ARTA is nothing but how much time the algorithm takes to run or to execute.

Based on the run time of the algorithm the efficiency of the algorithm is determined , this will be the deciding factor whether your algorithm is good or bad.

Based on ARTA , a algorithm can be improved to get better efficiency compared to your previous algorithm.


Practical Use Of Recursion Methodology

Where we use Recursion in Practical ?

Recursion is  heavily used in various areas.


  • We use in Stack example : Fibonacci Series
  • We use in Trees .  For Traversal , Insertion , Deletion , Searching.
  • We use in Quick Sort and Merge Sort.
  • Divide and Conquer -> Where bigger problem is divided into smaller chunks . Smaller chunks will be similar mostly.
  • In Dynamic Programming we use recursion where we divide bigger problem and solve smaller chunks and use to solve the bigger problem. 


   

AWS BASICS

Cloud Concepts :

Cloud Services :

In general these are called as Hosted Services and broken into three categories :

1. IaaS - Infrastructure as a Service.
2. PaaS - Platform as a Service.
3. SaaS - Software as a Service.

Difference between these three services lies in level of abstraction and Virtualization provided.

There are many components which comes into picture when we are talking about.  They are

 Low Level Components         (Low Level Components)

             Servers ,  Load Balancers  , File Storage , Networking.

Components relies on Low level components (Mid Level Components)

             Runtime (Language used to code)
             OS   (Os that runs on Load balancers and servers.)

On top of all : (High Level Components)

Application Data
Data

In order to do rapid administration and rapid application development .

Cloud came into picture.


IaaS provides services for Low Level Components.

PaaS provides services for Low Level and Mid Level Components.

SaaS provides services for Low , Mid and High Level Components.


How To Install Scala On MACOS


How to Install Scala on macOS
Step 1: Check for installation of Java Development Kit (JDK)
From a Terminal window, type:
$java –version

If it is already installed, skip to step 4.

Otherwise, download and install the JDK from http://www.oracle.com/technetwork/java/javase/
downloads/index-jsp-138363.html.

Step 2: Set environment variables for Java
export JAVA_HOME=/usr/local/java-current
export PATH=$PATH:$JAVA_HOME/bin/


Step 3: Verify install
Close and re-open the Terminal window, and type:
$java –version

Sample results
java version "11.0.3" 2019-04-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.3+12-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.3+12-LTS, mixed mode)


Step 4: Install Scala and SBT

To install, you must have an installation manager such as Homebrew (available at homebrew.sh).

From a Terminal window, type:
$ brew install scala
$ brew install sbt


Step 5: Add Scala to environment variables
To set up your environment variables on a Mac, you need to add these commands to your .bash_
profile file, which is located in your home directory. (Note: make sure that you don’t have hidden
files selected.)


export SCALA_HOME=/usr/local/share/scala
export PATH=$PATH:$SCALA_HOME/bin


Close and re-open the Terminal window, and type the following to verify the install: scala -version

Spring Microservices

Microservices became a popular choice for implementing applications which need to be highly scalable , reliable and deployable.


Many high scale systems started moving towards Microservices architecture.

Ex : Amazon , Netflix , Uber , LinkedIn, Twitter etc...


Spring Framework provides required components and environment for developing microservices in a simple and easy way.

We will learn creating , packaging and deploying microservices using spring boot and spring cloud.

Featured Post

H1B Visa Stamping at US Consulate

  H1B Visa Stamping at US Consulate If you are outside of the US, you need to apply for US Visa at a US Consulate or a US Embassy and get H1...