neelabhsingh
BAN USERI completed M.Tech (Software Engineering) for IIIT A.
My area of interest are Algorithms, Data Structure, Dbms, puzzle solving.
NEELABH SINGH
Email : neelabhsingh1986@gmail.com Address : Room No-501, Reddymaa PG, Rupena
Mobile : +91-9738088712 Agrahara Bangalore-68
Educational Qualifications:
Degree/ Certificate Institute CGPA
M.Tech (Software Engineering) IIIT Allahabad, Batch of 2013 8/10
B.Tech (CSE) JSSATE Noida, Batch of 2010 60%
Areas of Interest
Algorithms, Data Structure, Operating System, Programming and puzzles and DBMS
M.Tech Projects, IIIT Allahabad
Thesis: Comparison of Performance Evaluation of Authentication Mechanisms in SONATE and TCP/IP
June 12-Aug13
Brief: SONATE (Service Oriented Network Architecture) is a Future Internet Architecture. It is being developed in “German–Lab (G-Lab)”. This architecture is based on the SOA (Service Oriented Architecture). Implementation of Authentication Mechanisms is done in this clean slate architecture and performance of Authentication Mechanism in terms of execution time and throughput are compared in SONATE and TCP/IP architecture. This experimental result shows the validation authentication mechanism in SONATE architecture.
Languages/ Framework used: Java, BB Framework (SONATE architecture)
Project: “Future Stores” Supermarket Data Mining
Aug11-Nov11
Brief: Implementation of Association Rule Mining on given transitional data of super market sales transactions and prepare Discount policy by preparing Combo. It is based on Apriori algorithm.
Languages/ API/ database used: Java, Microsoft Excel 2007.
B.Tech Project, JSSATE Noida
Project: Online Programming Judge
Aug09-Dec09
Brief: It is web based application for online programming contest. User can compile and source code on server side and get result in successful compile, accepted, runtime error, time limit exceed. Based on the number of successful problem solved and execution time ranked of used can be made.
Language/ Tools/ Technologies: java, servlet, jsp, Mysql, Glassfish Web Server, NetBeans 6.0.1.
Technical Skills
Programming Languages : C, C++, core Java, Unix shell, Unix scripting, socket programming
DBMS : Oracle 9i, MySql
Programming Environment : Netbeans, Eclipse
Operating Systems : Linux (Ubuntu), Windows XP, 7
Beyond Curriculum
• Organize the online coding competition at college level
• GATE- 2013 Qualified. Amongst top 3.73% GATE 2011
• Won Gold Medal in Judo Karate at State Level
• Lawn Tennis, Badminton
- 2of 2 votes
AnswersGiven a Binary tree and value X. Find X in the tree and return its parent
- neelabhsingh in India for Hyderabad
X:
10
4 3
5 7 9 8
If X = 7, return 4| Report Duplicate | Flag | PURGE
Amazon SDE-2 Trees and Graphs - 0of 0 votes
AnswersYour are given two strings str1 and str2, you have to generate another unique string str3, which can only generated by these two string str1 and str2, no other string can generate that string str3. Some later point you have to retrieve back those two string str1 and str2 form that unique string str3.
- neelabhsingh in India for Hyderabad| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersYou are given an array, you have to replace each element of the array with product of the rest element. Example: {1,2,3}==> {6,3,2}
- neelabhsingh in India for Hyderabad| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
public class PairsWithSumInArray {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String [] str = br.readLine().split(" ");
int size = str.length;
int [] numbers = new int[size];
for(int i=0; i<size; i++){
numbers[i] = Integer.parseInt(str[i]);
}
List<Triplet> triplets = getAllTriplets(numbers);
Iterator itr = triplets.iterator();
while (itr.hasNext()){
Triplet triplet = (Triplet) itr.next();
System.out.println(triplet+", value("+numbers[triplet.getA()]+", "+numbers[triplet.getB()]+", "+numbers[triplet.getC()]+")");
}
}
public static List<Triplet> getAllTriplets(int [] array){
List<Triplet> triplets = new ArrayList<>();
HashMap<Integer, Integer> hashMap = new HashMap<>();
int size = array.length;
for(int i=0; i<size; i++){
hashMap.put(array[i], i);
}
for(int i=0; i<size-2; i++){
for(int j=i+1; j<size; j++){
int a = array[i];
int b = array[j];
if(hashMap.containsKey(a+b)){
triplets.add(new Triplet(i, j, hashMap.get(a+b)));
}
}
}
return triplets;
}
}
class Triplet{
private int a;
private int b;
private int c;
public Triplet(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
public int getA() {
return a;
}
public int getB() {
return b;
}
public int getC() {
return c;
}
@Override
public String toString() {
return "Index"+"("+a+","+b+","+c+")";
}
}
- neelabhsingh January 25, 2017No It we can't reason it change the array structure...
- neelabhsingh January 25, 2017import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class sort {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String [] str1 = br.readLine().split(" ");
String [] str2 = br.readLine().split(" ");
int size1 = str1.length;
int size2 = str2.length;
int []array1= new int[size1];
int []array2= new int[size2];
for(int i=0; i<size1; i++){
array1[i] = Integer.parseInt(str1[i]);
}
for(int j=0; j<size2; j++){
array2[j] =Integer.parseInt(str2[j]);
}
int [] result = mergeArray(array1, array2);
for(int value: result){
System.out.print(value+" ");
}
}
public static int [] mergeArray(int [] array1, int [] array2){
int [] result = null;
if(array1==null && array2==null){
return result;
}
if(array1==null){
return array2;
}
if(array2 ==null){
return array1;
}
int size1= array1.length;
int size2 = array2.length;
int k=0, i=0, j=0;
result = new int[size1+size2];
while (i<size1 && j<size2){
if(array1[i]<array2[j]){
result[k++] = array1[i++];
}else{
result[k++] = array2[j++];
}
}
while (i<size1){
result[k++] = array1[i++];
}
while (j<size2){
result[k++] = array2[i++];
}
return result;
}
}
My working code
public class MedianValueOfNewValues {
public static void main(String[] args) throws IOException{
Median median = new Median();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true){
int value = Integer.parseInt(br.readLine());
median.addNewNumber(value);
System.out.println("Median: "+ median.getMedian());
}
}
}
class Median{
PriorityQueue<Integer> minPriorityQueue = new PriorityQueue<>();
PriorityQueue<Integer> maxPriorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2-o1;
}
});
public void addNewNumber(int randomNumber){
//If both maxHeap and minHeap are equal.
if(maxPriorityQueue.size() == minPriorityQueue.size()){
//when size is not zero;
if(maxPriorityQueue.peek()!=null && randomNumber> minPriorityQueue.peek()){
maxPriorityQueue.offer(minPriorityQueue.poll());
minPriorityQueue.offer(randomNumber);
}else {
maxPriorityQueue.offer(randomNumber);
}
}else {
if(randomNumber < maxPriorityQueue.peek()){
minPriorityQueue.offer(maxPriorityQueue.poll());
maxPriorityQueue.offer(randomNumber);
}else {
minPriorityQueue.offer(randomNumber);
}
}
}
public double getMedian(){
if(maxPriorityQueue.size()==0){
return 0;
}
if(maxPriorityQueue.size() == minPriorityQueue.size()){
return (maxPriorityQueue.peek()+ minPriorityQueue.peek())/2d;
}else {
return maxPriorityQueue.peek();
}
}
}
- neelabhsingh January 20, 2017I solved through DFS approach
public class NumberOfGroupOf_1 {
public static int row =0;
public static int col =0;
public static void main(String[] args) {
int matrix[][]= new int[][]{
{1, 1, 0, 0, 0},
{0, 1, 0, 0, 1},
{1, 0, 0, 1, 1},
{0, 0, 0, 0, 0},
{1, 0, 1, 0, 1}
};
row = matrix.length;
col = matrix[0].length;
boolean [][] visited= new boolean[row][col];
System.out.println(groupOfOne(matrix, visited));
}
private static int groupOfOne(int [][] matrix, boolean [][] visited){
int groupOfOne =0;
for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
if(matrix[i][j]==1 && !visited[i][j]){
dfs(matrix, i, j, visited);
groupOfOne++;
}
}
}
return groupOfOne;
}
private static void dfs(int [][]matrix, int i, int j, boolean [][] visited){
int rowNbr[] = new int[] {-1, 0, 0, 1};
int colNbr[] = new int[] { 0, -1, 1, 0};
visited[i][j] = true;
for(int k=0; k<4; k++){
int x = rowNbr[k]+i;
int y = colNbr[k]+j;
if(isSafe(matrix, visited, x, y)){
dfs(matrix, x, y, visited);
}
}
}
private static boolean isSafe(int [][] matrix, boolean [][] visited, int i, int j){
if((i>=0 && i<col) && (j>=0 && j<row) && !visited[i][j] && matrix[i][j]==1){
return true;
}else {
return false;
}
}
}
This can be solved using State Pattern
Demo: http://ideone.com/zg3uxV
public interface AtmMachineState {
void insertDebitCard();
void ejectDebitCard();
void enterPinAndWithdrawMoney();
}
public class NoDebitCardState implements AtmMachineState{
@Override
public void insertDebitCard() {
System.out.println("Debit Card is inserted");
}
@Override
public void ejectDebitCard() {
System.out.println("No Debit Card in the slot, so you can't eject card");
}
@Override
public void enterPinAndWithdrawMoney() {
System.out.println("No Debit Card in ATM, so you can't enter pin and password");
}
}
public class HasDebitCardState implements AtmMachineState{
@Override
public void insertDebitCard() {
System.out.println("Debit Card is already in the ATM, so you can't insert another");
}
@Override
public void ejectDebitCard() {
System.out.println("Debit card is ejected");
}
@Override
public void enterPinAndWithdrawMoney() {
System.out.println("Pin Card entered correctly, and money has been withdrawn");
}
}
public class AtmMachine implements AtmMachineState {
private AtmMachineState atmMachineState;
public AtmMachine(){
atmMachineState = new NoDebitCardState();
}
public AtmMachineState getAtmMachineState() {
return atmMachineState;
}
public void setAtmMachineState(AtmMachineState atmMachineState) {
this.atmMachineState = atmMachineState;
}
@Override
public void insertDebitCard() {
atmMachineState.insertDebitCard();
}
@Override
public void ejectDebitCard() {
atmMachineState.ejectDebitCard();
if(atmMachineState instanceof HasDebitCardState){
AtmMachineState noDebitCardState = new NoDebitCardState();
setAtmMachineState(noDebitCardState);
System.out.println("ATM Machine internal state has been moved to"+atmMachineState.getClass().getName());
}
}
@Override
public void enterPinAndWithdrawMoney() {
atmMachineState.enterPinAndWithdrawMoney();
}
}
public class Client {
public static void main(String[] args) {
AtmMachine atmMachine = new AtmMachine();
System.out.println("ATM Machine Current state"+ atmMachine.getClass().getName());
System.out.println();
atmMachine.enterPinAndWithdrawMoney();
atmMachine.ejectDebitCard();
atmMachine.insertDebitCard();
System.out.println("\n ---------------");
System.out.println("ATM Machine Current State"+ atmMachine.getClass().getName());
System.out.println();
atmMachine.enterPinAndWithdrawMoney();
atmMachine.insertDebitCard();
atmMachine.ejectDebitCard();
}
}
Here test cases handled
Case 1: when no zero
ex: 1 2 3 4 5 => 120, 60, 40, 30, 24
Case 2: when one zero
ex: 1 2 3 0 => 0, 0, 0, 6
Case 3: when two zero
ex: 1 0 0 2 => 0, 0, 0, 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class ProductArray {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String []inString = br.readLine().split(" ");
int len = inString.length;
int [] intArray = new int[len];
int i=0;
for(String str: inString){
intArray[i] = Integer.parseInt(str);
i++;
}
int [] newProductArray = generateNewArray(intArray);
for(int value: newProductArray){
System.out.print(value+" ");
}
}
public static int [] generateNewArray(int [] array){
int oneZero = 1;
int allProduct = 1;
int zeroCount = 0;
int len = array.length;
for(int i=0; i<len; i++){
if(array[i]==0){
if(zeroCount==0){
zeroCount = 1;
}else{
allProduct = 0;
zeroCount = 2;
}
}else {
allProduct*=array[i];
}
}
int [] newArray = new int[len];
if(zeroCount == 2){
Arrays.fill(newArray, 0);
}else {
for(int i=0; i<len; i++){
if(zeroCount ==1){
if(array[i]==0){
newArray[i] = allProduct;
}else {
newArray[i] = 0;
}
}else{
newArray[i] = (int)allProduct/array[i];
}
}
}
return newArray;
}
}
#include <iostream>
using namespace std;
struct node{
int data;
struct node *left;
struct node *right;
struct node *nextRight;
}
void connectRightUtil(struct node * root){
if(root==NULL)// if there is Node is NULL
return;
if(root->left==NULL && root->right==NULL){// if there is only one Node
root->nextRight=NULL;
return;
}
connectRight(root);
}
void connectRight(struct node root){
if(root==null)
return;
if(root->left!=NULL){
if(root->right!=NULL){// if right child is not NULL then just put "root->left->nextRight=root->right;"
root->left->nextRight=root->right;
} else{
struct node * result=getRight(root);// get rightmost nextRight Node
if(root->nextRight!=NULL){
root->left->nextRight=right->left? result->left:(result->right?result->right:NULL);
}
else{
root->left->nextRigh=NULL;
}
}
}
if(root->right!=NULL){
root->right->nextRight=right->left? result->left:(result->right?result->right:NULL);
}
connectRight(root->left);
connectRight(root->right);
}
struct node * getRight(struct Node * root){
while(root->left==NULL && root->right==NULL root->nextRight!=NULL)
root=root->nextRight;
return root;
}
- neelabhsingh March 04, 2015K, how you handle this test case 1,2,3,0
- neelabhsingh February 20, 2015K, wht about 1,2,3,0
- neelabhsingh February 20, 2015boolean canBeExpressedInP&Q(int N){
int [] array=new int[(int)Math.sqrt(N)];// create array to count the number of prime factor.
int n=N;
Arrays.fill(array,0);// fill with zero
for(int i=2;i<=Math.sqrt(N);i++){ // N=216=> 2*108(N=108) that's why Math.sqrt(N)
while(N%i==0){
array[i]++;// count number of prime like 216=2*2*2*3*3*3, array[2]=3 and array[3]=3
N=N/i; // divide N every time we get any prime factor
}
}
//Now check array if all elements are equal excluding zero element.
int max=0;
for(int i=2; i<sqrt(n);i++){
if(array[i]!=0 && max==0){// first time max is initialize with 3, for N=216,
max=array[i];
}
else if(array[i]!=0 && array[i]!=max){
return false;
}
}// end of for loop., array[0]=0, array[1]=0, array[2]=3, array[3]=3;
return true;
}
public class FirstNonRepeatedCharacterEfficient {
public static void main(String [] args){
CharCountAndPosition [] array=new CharCountAndPosition[256];
for(int i=0;i<256;i++)
{
array[i]=new CharCountAndPosition();
}
Scanner scan=new Scanner(System.in);
String str=scan.next();
int len=str.length();
for(int i=0;i<len;i++){
char c=str.charAt(i);
int index=c-'a';
int frequency=array[index].frequencyOfchar;
if(frequency==0)
array[index].firstIndex=i;
array[index].frequencyOfchar=frequency+1;
//System.out.println(c+" "+array[index].frequencyOfchar);
}
boolean flag=false;
int firstPosition=Integer.MAX_VALUE;
for(int i=0;i<256;i++){
if(array[i].frequencyOfchar==1){
//System.out.println("character="+(char)(i+(int)'a'));
if(firstPosition> array[i].firstIndex){
firstPosition=array[i].firstIndex;
flag=true;
}
}
}
if(flag==true)
System.out.println(str.charAt(firstPosition));
else
System.out.println("There is no such type of character");
}
}
class CharCountAndPosition{
int firstIndex;
int frequencyOfchar;
}
- neelabhsingh November 05, 2014public class FirstNonRepeatedCharacterEfficient {
public static void main(String [] args){
CharCountAndPosition [] array=new CharCountAndPosition[256];
for(int i=0;i<256;i++)
{
array[i]=new CharCountAndPosition();
}
Scanner scan=new Scanner(System.in);
String str=scan.next();
int len=str.length();
for(int i=0;i<len;i++){
char c=str.charAt(i);
int index=c-'a';
int frequency=array[index].frequencyOfchar;
if(frequency==0)
array[index].firstIndex=i;
array[index].frequencyOfchar=frequency+1;
//System.out.println(c+" "+array[index].frequencyOfchar);
}
boolean flag=false;
int firstPosition=Integer.MAX_VALUE;
for(int i=0;i<256;i++){
if(array[i].frequencyOfchar==1){
//System.out.println("character="+(char)(i+(int)'a'));
if(firstPosition> array[i].firstIndex){
firstPosition=array[i].firstIndex;
flag=true;
}
}
}
if(flag==true)
System.out.println(str.charAt(firstPosition));
else
System.out.println("There is no such type of character");
}
}
class CharCountAndPosition{
int firstIndex;
int frequencyOfchar;
}
public class FirstNonRepeatedCharacterEfficient {
public static void main(String [] args){
CharCountAndPosition [] array=new CharCountAndPosition[256];
for(int i=0;i<256;i++)
{
array[i]=new CharCountAndPosition();
}
Scanner scan=new Scanner(System.in);
String str=scan.next();
int len=str.length();
for(int i=0;i<len;i++){
char c=str.charAt(i);
int index=c-'a';
int frequency=array[index].frequencyOfchar;
if(frequency==0)
array[index].firstIndex=i;
array[index].frequencyOfchar=frequency+1;
//System.out.println(c+" "+array[index].frequencyOfchar);
}
boolean flag=false;
int firstPosition=Integer.MAX_VALUE;
for(int i=0;i<256;i++){
if(array[i].frequencyOfchar==1){
//System.out.println("character="+(char)(i+(int)'a'));
if(firstPosition> array[i].firstIndex){
firstPosition=array[i].firstIndex;
flag=true;
}
}
}
if(flag==true)
System.out.println(str.charAt(firstPosition));
else
System.out.println("There is no such type of character");
}
}
class CharCountAndPosition{
int firstIndex;
int frequencyOfchar;
}
- neelabhsingh November 05, 2014/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
int count_SetBit=countSetBit(num);
System.out.println(count_SetBit);
}
public static int countSetBit(int num)
{
int count=0;
int mask=0x0001;
while(Math.abs(num)>0)
{
if((num&mask)==1)
count++;
num>>>=1;
}
return count;
}
}
This Solution works for negative and positive number both.
your code is maximum depth.
- neelabhsingh October 18, 2013above solution will be fail if doubly linked list has duplicate node value. and this condition
if(fp->next!=NULL)
fp=fp->next;
should not use because it is circular linked list....
- neelabhsingh May 20, 2013
Repmarktrejjo, Data Engineer at Accolite software
I’m Mark.I believe life is too short to be serious all the time, so if you cannot laugh ...
Repcamillerharry, Data Engineer at Student
Hi, I am Camille from Easton USA. Currently, I am working as Staff assistant at Northern Star company. A managed ...
- neelabhsingh January 25, 2017