Skip to content

Instantly share code, notes, and snippets.

View Sudip7's full-sized avatar

Sudip Nayak Sudip7

  • TCS
  • Bangalore
View GitHub Profile
## Sample algorithms logic reference
Array:
* Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.
code snippet:
void leftRotate(int arr[], int d, int n)
{
* What's the distributed system ?
** It's a system that's spread over more than location.
* why distributed system ?
** The purpose of distributed system, or dividing it over more than one physical location,
is to fix the machine and organisational perfomance problem by using two powerful operational and architectual concepts:
*data copying and decoupling*
What's lambda expression ?
* Lambda experession is java's way introducing functional programming into the language.
* Lambda removes the bulkiness inner class with more compact solution.
This simple horizontal solution solves the "vertical problem" presented by inner classes.
* Lambdas treat functionality as a method argument or code as data.
* Lambda works with functional interface i.e. an interface with single abstract method(SAM)
* Typical structure any lambda experession
Step 1
Create an interface.
Shape.java
public interface Shape {
void draw();
}
Step 2
Create concrete classes implementing the same interface.
@Sudip7
Sudip7 / multithread.adoc
Last active October 21, 2018 13:21
Java multithreading question and ans
  1. Can the keys in Hashing data structure be made Mutable?

    • The answer is NO. If we make the keys mutable then the hashcode() of the key will no more be consistent over time which will cause lookup failure for that object from the data structure.

    • As bucket location is calculated based on key’s hashcode(), any change in key value will the change the hashCode calculation so is the problem in finding the stored object.

    • Never make changes to the hashmap’s key, otherwise the associated object can not be fetched using get() method.

    • Though it will be accessible using other methods which iterate over the entire collection.

  2. Here are 1 million trades, you need to check if a given trade exists in those trades or not. Which Collection would you chose to store those 1 million trades and why?

@Sudip7
Sudip7 / CleanArchitecture.md
Created September 20, 2018 15:28 — forked from ygrenzinger/CleanArchitecture.md
Summary of Clean Architecture by Robert C. Martin

Summary of book "Clean Architecture" by Robert C. Martin

Uncle Bob, the well known author of Clean Code, is coming back to us with a new book called Clean Architecture which wants to take a larger view on how to create software.

Even if Clean Code is one of the major book around OOP and code design (mainly by presenting the SOLID principles), I was not totally impressed by the book.

Clean Architecture leaves me with the same feeling, even if it's pushing the development world to do better, has some good stories and present robust principles to build software.

The book is build around 34 chapters organised in chapters.

Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array
//Code
import React from 'react';
import Chance from 'chance';
class Detail extends React.Component {
render() {
return <p>Hello, {window.Chance.first()}!</p>;
}
}
//Code
import React from 'react';
import Chance from 'chance';
class Detail extends React.Component {
render() {
return <p>Hello, {window.Chance.first()}!</p>;
}
}
@Sudip7
Sudip7 / Dijkstra.java
Created August 8, 2017 03:43
Dijkstra shortest path algorithm
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
public class Dijkstras {
public static void main(String[] args) {