algolearner
BAN USER
public class CareerCup_Amazon_FindGivenNumberInTree {
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeNode root = new TreeNode(0);
TreeNode o1 = new TreeNode(1);
TreeNode t2 = new TreeNode(1);
TreeNode t3 = new TreeNode(3);
TreeNode f4 = new TreeNode(4);
TreeNode f5 = new TreeNode(4);
TreeNode s6 = new TreeNode(6);
TreeNode s7 = new TreeNode(7);
TreeNode e8 = new TreeNode(8);
TreeNode n9 = new TreeNode(9);
root.left = o1;
root.right = t2;
o1.left = t3;
o1.right = f4;
t2.left = f5;
t2.right = s6;
t3.left = s7;
t3.right = e8;
f5.left = n9;
CareerCup_Amazon_FindGivenNumberInTree o = new CareerCup_Amazon_FindGivenNumberInTree();
o.hasNumberInTree(root,149);
}
public boolean hasNumberInTree(TreeNode root,Integer n){
List<Integer> nL = new ArrayList<>();
while(!(n<10)){
int nR = n%10;
n = n/10;
nL.add(0,nR);
}
nL.add(0,n);
return hasNumberInTreeHelper(root,nL,-1,0,0);
}
/* ex:
3
4 5
6 7 8 9*/
public boolean hasNumberInTreeHelper(TreeNode root,List<Integer> nL,int previosLevel,int level,int i){
if(root==null)
return false;
if(root.val == nL.get(i)){
if(previosLevel==-1)
previosLevel = level;
else if(level-previosLevel>1)
return false;
previosLevel = level;
i=i+1;
}
if(i==nL.size()){
return true;
}
if(hasNumberInTreeHelper(root.left, nL,previosLevel,level+1,i) || hasNumberInTreeHelper(root.right, nL,previosLevel,level+1,i))
return true;
return false;
}
}
- algolearner January 07, 2017package com.practice.algo.and.ds.bitmanipulation;
public class BitMask {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] arr = {{0,0,0,1},{1,1,1,1},{0,0,1,1},{0,1,1,1}};
int n = 1;
for(int i =0;i<3;i++){
n |=(n<<1);
}
int count = Integer.MIN_VALUE;
for(int i=0;i<arr.length;i++){
String str = "";
for(int j=0;j<arr.length;j++){
str+=arr[i][j];
}
int c= Integer.bitCount(Integer.parseInt(str, 2) & n);
if(c > count){
count = c;
}
}
System.out.println(count);
}
}
Below line is giving ClassCastException for the one dimensional array
Object obj1[] = (Object[]) cls.cast(obj);
Thanks Tim for an amazing solution. Thats what I was looking for.
- algolearner September 03, 2014I wan to know if this can be solved by set of equations or BFS ?
Here I am not concerned with this particular input but generic input and moves.
Any specific algorithms...or implementation to solve this. BFS or Equations ?
- algolearner August 19, 2014String str = "111100";
String str2 = "000100";
String str3 = "000010";
int kk=0;
for(int i=str.length()-1;i>=0;i--){
if(str.charAt(i)=='1'){
a = a | (1<<kk);
}
kk=kk+1;
System.out.println(a);
}
kk=0;
int b=0;
for(int i=str2.length()-1;i>=0;i--){
if(str2.charAt(i)=='1'){
b = b | (1<<kk);
}
kk=kk+1;
System.out.println(b);
}
kk=0;
int c=0;
for(int i=str3.length()-1;i>=0;i--){
if(str3.charAt(i)=='1'){
c = c | (1<<kk);
}
kk=kk+1;
System.out.println(c);
}
System.out.println(c);
int aa[] = {a,b,c};
int N=3;
int M=6;
int K=5;
for(int i=1;i<(1<<N);i++){
int r =0;
for(int j=0;j<N;j++){
if((i & (1<<j)) !=0){
r = r | aa[j];
}
}
if(K==Integer.bitCount(r)){
System.out.println("found");
break;
}
}
how ll you get 0 and 1
- algolearner August 07, 2013What about doing bit masking and chcking set bits if they add upto required sum.
- algolearner June 16, 2013When we have use some personaised object (not String,Integer etc which already implements these functions)as a key in Hash related data structures i.e. HashMap,TreeMap, HashSet etc then for correct implementation of this key, We need to implement these functions.
It is good practice to implement both these functions together.
Please verify my solution. I could solve it by BruteForce only. Any algorithm can be applied on this? Experts please help
- algolearner November 21, 2012package com.tc.graphs;
import java.util.Set;
import java.util.TreeSet;
public class RectangleBorderOnes {
/**
* @param args
*/
Set<Integer> t = new TreeSet<Integer>();
int[][] array = { { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 0 }, { 1, 1, 1, 1, 0 }, { 0, 0, 1, 0, 0 } };
private void addEdge(int start,int end){
array[start][end] = 1;
}
private int calculate(){
for(int row=0;row<array.length;row++){
for(int colum=0;colum<array[row].length-1;colum++){
//System.out.println(row + "" +colum);
if((array[row][colum]==1)){
for(int columCol=colum+1;columCol<array[row].length;columCol++){
//System.out.println(colum + "" + columCol);
int flag = 0;
for(int i=colum;i<=columCol;i++){
if(array[row][i]==0){
flag=0;
break;
}else {
flag=1;
}
}
if(flag==1){
checkOnes(row,colum,columCol);
}
}
}else{
// break;
}
}
}
Object[] result = t.toArray();
return (Integer)result[result.length - 1];
}
private void checkOnes(int row,int colum,int columCol) {
// TODO Auto-generated method stub
// Now we got the width
int width = columCol - colum + 1;
for(int i = row+1;i<array.length;i++){
int flag = 1;
for(int k = row+1;k<=i;k++){
if(array[k][colum]==0 || array[k][columCol]==0){
flag=0;
}
}
if(flag==1){
int cc=1;
for(int j = colum+1;j<=columCol-1;j++){
if(array[i][j]==0){
cc=0;
}
}
if(cc==1){
//System.out.println("rectangle Completed");
int area = (i-row+1)*(columCol-colum+1);
//System.out.println(area);
t.add(area);
}
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
RectangleBorderOnes r = new RectangleBorderOnes();
int res = r.calculate();
System.out.println(res);
}
}
RepArnavPatel, abc at A9
Dedicated and energetic bakery assistant with a passion for flavor and a love for creating. Professional and dependable with more ...
RepIn 2008 I was licensing race cars in Los Angeles, CA. What gets me going now is promoting husband vashikaran ...
Repdeloresrdaniels, Cloud Support Associate at JDA
Crossed the country marketing wool in Nigeria. Was quite successful How to Get Girlfriend Back By Vashikaran Mantra . Spent a ...
RepGirikScott, Android Engineer at ABC TECH SUPPORT
I write stories of families based on the unique experience that early settlers faced in this country. I have a ...
RepRutviLopez, abc at A9
I have demonstrated skills in written communication with multiple award winning pieces and a strong willingness to revise and edit ...
Repemileyrollens, Architect at Cloudera
I am Emily, a detail-oriented and certified junior Architect who excels at developing construction drawings, generating 3D models. I love ...
Reptracyremly, Anesthesiologist at Ness
I am Tracy, working as an Anesthesiologist handles surgical patients and their pain relief during procedures.Rather than my job ...
Repaanyagill, café manager at The Best Cafe
Unshakable dedication to bringing out the best in a restaurant and its employees, while taking exemplary care of guests and ...
Repmarygaustria, Analyst at ADP
I am Mary from Los Angeles, USA. I am working as a Manager in Fragrant Flower Lawn Services company. I ...
Repgeraldgloria02, Android test engineer at Achieve Internet
I am a personal trainer. I design programs and provide nutritional advice and coaching. I wanted to share my knowledge ...
Repmandybourne5463, Accountant at ABC TECH SUPPORT
MandyBourne, and I am a Computer typesetter and I love my work. Apart from this, today I am doing new ...
RepHelenBMartin, Android Engineer at ABC TECH SUPPORT
I am an avid reader and a leader and participant in a community book club. My reading Kamakhya Mandir Tantrik ...
RepAayshaRosie, HTML Freshers at Abs india pvt. ltd.
Aaysha , a book editor with 4 years of experience with increasing readership and developing skilled writers. At the Daily Record ...
Replindagwingard, Android test engineer at ABC TECH SUPPORT
Hello, my name is Larry and I am a commercial loan officer. We are commercial loan officers who specialize in ...
RepNaomiAdams, abc at 8x8
Passionate educator for nearly 5 years with a strong desire to help students recognize the connection between learning and experience ...
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 ...
Repalicesreedg, Accountant at ADP
Hi my name is Alice and i am working in an IT company. I am working here from last 5 ...
Replisapyara, abc at 247quickbookshelp
I am motivated and organized professional with proven years of experience in mail services and industry having vast experience as ...
Repdubinalinda4, Animator at Apache Design
Hello, I am a school librarian from Lewistown USA. I work in public or private schools at elementary, middle and ...
RepSamiyahKate, Java Experienced at Agilent Technologies
I am Samiyah, having 3 years of experience in assessing, diagnosing, screening, and preventing language, speech, and swallowing disorders. I ...
Repronalddavis284, Accountant at ADP
As you may be able to infer from my professional background, I have a strong interest in mathematics and the ...
Repabig8485, Apple Phone Number available 24/7 for our Customers at ABC TECH SUPPORT
Hello, I'm Abigail and I'm from Hugo City. I maintain customer loyalty and keep a diverse group of ...
Repellaiyer15, Content Writer at Precious Moments
Committed to producing exceptional and creative types of content, including articles, internet content, advertisements, commercials, brochures, and publications. Experienced in ...
Repjacksssones433, Apple Phone Number available 24/7 for our Customers at A9
Proficient and creative WordPress developer with a strong history in website management and development. Experienced in SEO and PPC campaign ...
Repbarrondanielle057, Android test engineer at A9
My name is Danielle and I am working as a Contract manager. I love this job.and nowadays I am ...
Repkenneroce, Cheap Escort Service in Lajpat Nagar 8447779280 Call Girls at Persistent Systems
Hi, I am Kenne working as a LAN manager. One day, I read how to break up a couple from ...
Replyndaander9, Analyst at A9
My name is Anderson and I am a 24 years old trader born and currently working in New York, USA ...
RepRuthOrvis, AT&T Customer service email at 8x8
Hey I am Ruth Working as a branch manager in a bank.I have worked here for the last 4 ...
Reppamelajoung, Dev Lead at Absolute Softech Ltd
I have worked as a wedding photographer for the past two years, first as a photographer’s assistant and then ...
RepRobertBaumbach, Administrative Manager at Meridian Mechanical Services
Repjacksabjohne, Accountant at ABC TECH SUPPORT
Michael is a Biological Technician with 4 years of experience monitoring, characterizing, and quantifying riverine processes and habitat in the ...
Repethelsizer, SDET at ADP
I am Ethel , creative news writer with 5+ years of experience. Have great storytelling skills , wrote and delivered high quality ...
RepI am Rasha , C/C++ certified Computer Programmer with expert-level competency in JavaScript, HTML and JSP and more than 6 ...
Repcolettehenna, OOPS Freshers at Bosch
I am Colette , policy analyst at Sunflower Market , with 3 years of experience building and maintaining relationships with elected officials ...
Repbrandysolsen, Area Sales Manager at AMD
I am a Social butterflies who enjoy travel.Have fun doing this job and project an atmosphere that reflects Amazon ...
RepJennifer Crystal, Accountant at US
As I am an artist at Silverstone Spark have a creative mind and am a seasoned professional artist who focuses ...
Replusinisa67, Secretary at Melbourne
Skilled and experienced secretary in Teiscom company. Highly organized with a strong attention to detail and the ability to monitor ...
Repremiflo4, Dyeing at Fabric Dyeing Service
Mid-level hair stylist with five years of experience working with men’s and women’s hair as well as children ...
RepHelenHinkley, Accountant at 8x8
Dedicated English-Mandarin Chinese translator with years of experience working in professional and scientific communities. I am passionate about how to ...
RepBlakeRileyHomes, Analyst at Aristocrat Gaming
Blake Riley Homes is the leading interior designing and real estate home staging Orange County CA company.Our professional designs ...
Repriyanahobett, Sales Development Representative at Capgemini
I am Riyana , driven market researcher with over years of experience at Awthentikz , analyzing information in order to construct profiles ...
Replarryehickl, Associate at ABC TECH SUPPORT
I am a blogger in the Geek system operator . As an editor with a strong background in english and hindi ...
RepEmilRuiz, Data Engineer at Apple
Emil , an Experienced producer has been producing top-rated shows for five years running. Excels at defining and expanding target audience ...
RepRoyaltyAd is the top digital marketing company. We have a team of SEO experts that helps you to maximise your ...
Repamayalopez800, Accountant at A9
I am Amaya ,working in the field of training and development coordinator for three years, focusing on teaching English as ...
RepAahnaAllen, AT&T Customer service email at A9
I am a multilingual Judge with 5 years of combined experience in presiding over court proceedings, prosecuting cases, and tirelessly ...
Reppfisterruiz, Accountant at 247quickbookshelp
Door-to-door is a canvassing technique that is generally used for sales, marketing, advertising, evangelism or campaigning, in which I walk ...
RepRilynFreeman, Area Sales Manager at Knewton
Hi my name is Rilyn. Library assistant in Jeans Unlimited company. I help to keep libraries organised and efficient while ...
RepLucasMoore, AT&T Customer service email at 8x8
I am creative with many years experience in the Advertising-Account Director, I have strong attention to detail and ability in ...
Repearlenecnicely77, Animator at 247quickbookshelp
Hey, I'm a Receiving clerk. And I love my work. Apart from this, I am doing some new experiments ...
Reppaytonmorrison48, Data Scientist at ADP
I am working as a date entry keyar . I have many years of experience . The data entry manager is primarily ...
RepCamilaHill, Accountant at ADP
I am a performance-driven leader providing high-level administrative and operational support, coordinating schedules, preparing travel and documents, and exploring Surah ...
RepFurryReign, Questions - Problem Solving Round at Cerberus Capital
Furry , An Athletic Trainer with confidence that my 7 years of experience in various organizations and industries have given me ...
RepAasiHarris, abc at 8x8
I am a creative designer with innovative ideas and a unique approach to visuals. I am also a skilled painter ...
Reppedrospencerp, Blockchain Developer at 247quickbookshelp
My name is Pedro and I am a 28 years old Title abstractor . I research all documents and activities affecting ...
Repannavhedge4, AT&T Customer service email at ABC TECH SUPPORT
Hi everyone, I am from Worcester,USA. I currently work in the Argus Tapes & Records as Scientific illustrator . I love ...
RepNoraMiller, abc at A9
Confident and dedicated photographer with experience in both professional and freelance photography.. Prioritizes communication on the job to avoid errors ...
Repnnatashanaomi, Android test engineer at 247quickbookshelp
I am Marketing managers who play a crucial role in helping a business to promote and its customers. I manage ...
Repmarkemorgan007, Applications Developer at Big Fish
I am Mark From Fresno city in USA.I working as a tour guide and also help for make a ...
Repblancalross748, Android Engineer at ABC TECH SUPPORT
Hello I am a Highly-professional and talented Managing Editor with a solid experience in planning and directing editorial activities for ...
RepYuvaanBrown, abc at AMD
I am working as an art director in a lomni company. I have expert knowledge of adobe creative suite in ...
RepAakeshCruz, Accountant at Tinder
Exceptional knowledge of mathematical concepts, accounting and finance topics, tax code, and banking principles.Worked with clients and CFOs to ...
}
- algolearner August 15, 2017