sumit.polite
BAN USERSimply we can use kmp algoritham with time complexity O(LM).
L -; Length of the longest string
M-; Length of the list
Hi.
i think this is nothing but counting number of inversion in the array..
please correct me if i am wrong
can u clarify can we modify the array..or array is allways sorted..
- sumit.polite April 03, 2015I think without using quick sort we can do in o(N) TC bu using Boyer-Moore_Majority_Vote_Algorithm .. as i did please my comment...public class MajorityElement
- sumit.polite April 03, 2015package com.aorg.MyPractice.DS.Array;
public class MajorityElement {
/**
* @param args
*/
public static void main(String[] args) {
try{
int[] a = {2,5,3,5,5,3,5};
int ele = new MajorityElement().getMajority(a);
System.out.println(ele);
}catch(Exception ex){
ex.printStackTrace();
}
}
public int getMajority(int[] a){
try{
int count = 0;
int count1 = 0;
int ele = a[0];
for(int i=1; i <a.length ; i++){
if(count == 0){
ele = a[i];
count = 1;
}else{
if(ele == a[i]){
count++;
}else{
count--;
}
}
}
int ele1 = 0;
count = 0;
for(int i = 0; i <a.length ; i++){
if(ele == a[i]){
count++;
}else if(count1 == 0){
ele1 = a[i];
count1 = 1;
}else if(ele1 == a[i] && count1 < count){
count1++;
}else{
count1--;
}
}
System.out.println("2nd Majority element > "+ele1);
if(count > (a.length/2)){
return ele;
}else{
return -1;
}
}catch(Exception ex){
ex.printStackTrace();
}
return -1;
}
}
}
- sumit.polite April 03, 2015????????......
- sumit.polite March 03, 2015private void connectSameLevelNode1(TreeNode tree){
try{
if(tree == null){
return;
}
if(tree.getLeft() != null){
if(tree.getRight() != null){
tree.getLeft().setNext(tree.getRight());
tree.getRight().setNext(getNextPointer(tree));
}else{
tree.getLeft().setNext(getNextPointer(tree));
}
}else if(tree.getRight() != null){
tree.getRight().setNext(getNextPointer(tree));
}
connectSameLevelNode(tree.getLeft());
connectSameLevelNode(tree.getRight());
}catch(Exception ex){
ex.printStackTrace();
}
}
private TreeNode getNextPointer(TreeNode tree){
try{
TreeNode nextPointer = tree.getNext();
while(nextPointer != null){
if(nextPointer.getLeft()!=null){
return nextPointer.getLeft();
}
if(nextPointer.getRight() != null){
return nextPointer.getRight();
}
nextPointer = nextPointer . getNext();
}
return null;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
- sumit.polite February 28, 2015private void connectSameLevelNode1(TreeNode tree){
try{
if(tree == null){
return;
}
if(tree.getLeft() != null){
if(tree.getRight() != null){
tree.getLeft().setNext(tree.getRight());
tree.getRight().setNext(getNextPointer(tree));
}else{
tree.getLeft().setNext(getNextPointer(tree));
}
}else if(tree.getRight() != null){
tree.getRight().setNext(getNextPointer(tree));
}
connectSameLevelNode(tree.getLeft());
connectSameLevelNode(tree.getRight());
}catch(Exception ex){
ex.printStackTrace();
}
}
private TreeNode getNextPointer(TreeNode tree){
try{
TreeNode nextPointer = tree.getNext();
while(nextPointer != null){
if(nextPointer.getLeft()!=null){
return nextPointer.getLeft();
}
if(nextPointer.getRight() != null){
return nextPointer.getRight();
}
nextPointer = nextPointer . getNext();
}
return null;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
for get the minimum delivery man , find the intersection of the P1 and P2...
but i have doubt in complexity in the logic
please correct me if i am wrong...
We can use Hashing for UID and if these unique id is in large file then we can use hasing as well as file partioning according to avilable main memory..
please correct me if i a wrong
How i can get two string back after genrating...
as i thing..
it should be len(str1)+str1+len(str2)+str2..
please correct me if i am wrong..
Greate..JOb..
Thanks a lot ...
if we are matching query using suffix of the string then.. we can try using suffix tree or array.... i ll post ASAP.. for that...
- sumit.polite February 20, 2015this is nothing but part of pancake sorting... hoe u will get the answer when u will get to know pancake sorting...
- sumit.polite February 07, 2015this is nothing but part of pancake sorting... hoe u will get the answer when u will get to know pancake sorting...
- sumit.polite February 07, 2015correct......
becz we have N scientist and k black hole and one scientist can make query at most k black hole..
As in starting u r right we can sort M1,M2 and M3 after that can we use minHeap data structure to store all the data from all three machine and then , i can read MinHeap to store 1st 1/3rd record in M1 and then 2nd 1/3rd to M2 and then rest M3..please correct me if i am wrong.
Thanks u
Repamayahoyle, Associate at ABC TECH SUPPORT
Working as a Set Designer with 2+ years of experience in Audio Aid for vehicles and props including turns using ...
Replyndaander9, Analyst at A9
My name is Anderson and I am a 24 years old trader born and currently working in New York, USA ...
We can use Interval Tree or Segment Tree Data Structure ...
- sumit.polite January 24, 2017