Balajiganapathi S
BAN USER
Assuming the following structure of the binary tree
struct Node {
Node *left, *right;
};
We can write a recursive function to calculate the maximum depth of a node:
First compute the maximum depth of the two child nodes and take the maximum out of them. This gives us the maximum depth of the children. Now we add 1 to it (for the current node) and this will be the maximum depth starting from the current node. We call the function with the root of the binary tree to get the maximum depth of the whole tree.
int depth(Node *cur) {
if(cur == NULL) return 0;
return 1 + max(depth(cur->left), depth(cur->right));
}
You can use a recursive function which remembers two things: the current index in the input string and the number we have got so far. From here, we can do two things: we can either add the current digit to the number we have so far or we can start a new number.
string s;
int solve(int idx, int sofar) {
if(sofar > 26) return 0;
// There can't be leading zeros
if(sofar == 0) return 0;
// This is a valid splitting of the string
if(idx == (int)s.size()) return 1;
int ret = solve(idx + 1, sofar * 10 + s[idx] - '0');
ret += solve(idx + 1, s[idx] - '0');
return ret;
}
The answer is solve(1, s[0] - '0')
Note that the states may repeat so you can use memoisation to reduce the time complexity to O(n)
This can be solved using dfs.
Consider each person as a node and each connection as an edge between the two persons' corresponding nodes. Then it is easy to see that a community is a connected component in this graph. So use dfs (bfs will work too) to find the number of nodes in each community and if it is even then output that community.
RepGwen Camacho, Accountant at ABC TECH SUPPORT
Gwen , a Director of Nursing with 6+ years of experience with excellent supervising and organizational skills in a large hospital ...
RepNinaHedge, Android Engineer at ABC TECH SUPPORT
Hello, I am a Book writer who uses their content creation and verbal skills to produce articles, blogs or professional ...
Reptargienaron, Public relations coordinator at Total Quality
I am a public relations coordinator . Planning publicity strategies and campaigns. writing and producing presentations and press releases. I explore ...
RepEllenaSimon, Animator at ABC TECH SUPPORT
Hello I am an event planner and I have been working in this field for almost 5 years. For a ...
Repsheilabjones023, abc at 8x8
Hello,I am a Press operator. I completed my degree from Chicago and now am a Press operator in Lechmere ...
RepAriaScott, abc at 247quickbookshelp
I am a qualified medical representative who has been in the industry for many years and has proven sales experience ...
Reppamulapaya2, Area Sales Manager at Alcatel Lucent
Jorie , a Customer services manager with more than 6 years' experience working is responsible for managing the relationships between an ...
RepLoriEver, Applications Developer at ASAPInfosystemsPvtLtd
LoriEver a Rancher working at William Wanamaker & Sons. It's been almost 6-10 years that he has been working this ...
RepRuzilStaker, Java Freshers at Digital Merkating
Ruzil , a Publicity Specialist with over four years in PR. Also a communicator adept at managing all public relations efforts ...
RepLiamLee, abc at ADP
Proven leadership skills that have helped projects get completed within the time and budget constraints, Dedication to following appropriate safety ...
RepLisaNoto, Android Engineer at ADP
Annie has nearly 10 years of experience working on anadromous and estuarine fishery issues in California. She serves as a ...
RepDaisyRoss, Video game designer at A9
Seeking lead game programmer and position to utilize knowledge and skills to advance portfolio and potential for increased responsibility. Explore ...
RepDonnaTyler, HR Executive freshers at Bloomberg LP
I am Donna , a travel counselor who advises clients on travel options and tour packages, makes bookings , prepares tickets and ...
RepKianaEmmert, SDE1 at Home Depot
I am Kiana , an Entertainment Journalist, having 5 years of experience, in my career I have covered a lot of ...
RepJoseElkins, Animator at ASU
I am working as Human Resources Associates, and my duties are for obtaining, recording, and interpreting human resources information within ...
RepJamesGustin, Analyst at A9
Veteran technical assistant with over 5 years’ experience in the industry. Extensive knowledge and education in a variety of hardware ...
Repjoeevansjoe6, Repairer at Monlinks
I have been functioning as a repairman at monlinks organization for a long time . Here I learn numerous things . My ...
RepSuzaneVenable, Applications Developer at 247quickbookshelp
I am an employment manager typically in charge of planning the hiring processes, setting guidelines and timelines, and establishing budgets ...
RepJudeSandin, Associate at Absolute Softech Ltd
My name is JudeSandin . I am working at Bold Ideas as a Web designer. With 5 years experience . I am ...
Repeffiefranke, Mail clerk at Envirotecture Design
Hello, I am Effie Mail clerk . I sort mail by department and category, utilizing sorting machines and similar administrative technology ...
RepAmaraPerez, Android Engineer at Allegient
I am an outgoing and motivated flight attendant with a strong customer-oriented approach and excellent communication skills.I am always ...
Repwastonlare, Java Developer at Broadsoft
Waston , an executive in the finance and accounting area of the industry with expertise in teaching, training and managing my ...
Repjepatricia581, Accountant at 247quickbookshelp
We business management is the coordination and organization of business activities. Business managers oversee operations and help employees reach their ...
Reppamelajones9873, Area Sales Manager at Facebook
Hello I am Pamela Jones. I am an Animal Control Worker Here, Animal control officers are generally employed by a ...
RepEileenBrown, Android Engineer at ABC TECH SUPPORT
Eileen Brown and I am a Product designer.And nowadays I am doing new research like istikhara for love marriage ...
RepAnaCardenas, Android Engineer at Allegient
Working as a Window clerk at EnviroSource Design for almost 10 years . Here I help people to guide . End a ...
RepDarikaLee, Applications Developer at ADP
I am a knowledgeable and performance-driven Network Administrator with a comprehensive background in managing servers, maintaining software/hardware, performing backups ...
Repshushichiku, Associate at ASU
PaulKenda is a Farmworker working at Jackhammer Technologies . I am a specialist in my work here. I manage different things ...
RepYuvaanBrown, abc at AMD
I am working as an art director in a lomni company. I have expert knowledge of adobe creative suite in ...
RepFernBryant, Android Engineer at ABC TECH SUPPORT
I FernBryant working at Naugles as a Financial consultant . I have 5 years of experience . I also guide people regarding ...
RepNorinaKen, iOS Developer at ASU
Norina, a certified ENP and Emergency Medical Dispatcher with 7 + years of work experience got the opportunity to join the ...
How is the result computed? Does an element needs to pass all of the filters or any one of them?
- Balajiganapathi S August 14, 2014