0% found this document useful (0 votes)
7 views4 pages

Interview

Uploaded by

Kashish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Interview

Uploaded by

Kashish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

4

3 2
6 7 8 1
21 5

4 3 ans 4min

int ParentNode( TreeNode root ){


If ( root == null ){
Return 0;
}
Map <TreeNode> mpp;
mpp.push(root);

Int leftheight = ParentNode(root.left);


Int rightheight = ParentNode(root.right);

Given an array ‘arr’ of integer numbers, ‘arr[i]’ represents the number of pages in the ‘i-th’ book.

There are ‘m’ number of students, and the task is to allocate all the books to the students.

Allocate books in such a way that:

1. Each student gets at least one book.


2. Each book should be allocated to only one student.
3. Book allocation should be in a contiguous manner.

You have to allocate the book to ‘m’ students such that the maximum number of pages assigned
to a student is minimum.

If the allocation of books is not possible, return -1.

Input: ‘n’ = 4 ‘m’ = 2


‘arr’ = [12, 34, 67, 90]

Output: 113
1

2 5

4 3
vector<int> Bfs( Node V , vector <int> adj []){

Int n = adj.size();
int vis [n] = {0} ;
Queue <int> q;
q.push(V);
Vis [ V ] = 1;
Vector <int> bfs;

while(!q.empty()){
Int node = q.front();
q.pop();
bfs.push_back(node);

for( auto it : adj[node] ) {


If ( !vis[ it ] ) {
Vis [ it ] = 1;
q.push( it );
}
}
}

Return bfs;
vector<int> breathFirstSearch(Node* v,vector<int> &adj[]){
​ int n = adj.size();

​ int visit[n] = {0};


​ queue<int> nodes;
​ visit[v] = 1;
​ nodes.push(v);

​ vector<int> ans;
​ while(!nodes.empty()){
​ ​ int node = nodes.front();
ans.push_back(node);
for(auto it:ad[node]){
​ if(!visit[it]){
​ ​ visit[it]=1;
​ ​ nodes.push(it);
}
}​
}
return ans;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy