AP 2 - Gandu
AP 2 - Gandu
AP 2 - Gandu
Objective (a): Given a pointer to the root of a binary tree, print the top view of the
binary tree.
The tree as seen from the top the nodes, is called the top view of the tree.
Code (a):
Code (b):
void inOrder(Node *root)
{
if(root->left)
{
inOrder(root->left);
}
cout << root->data << '
'; if(root->right)
{ inOrder(root->right);
}
}
Output (b):
Learning Outcomes:
• Learnt to build the logic to find out the solution of problem and achieve all
test cases.
• Learnt to interpret the problem and find out better approach to solve
particular problem.
• Learnt the concept and implementation of Tree.
• To gain critical understanding of problem solving on Hackerrank platform.
Time Complexity:
Worst-case performance: O(n)
Best-case performance: O(1)
Average performance: O(log n)
Worst-case space complexity: O(1)
Experiment 2.3
2. Objective
string pangrams(string s) {
map<char,int> m;
transform(s.begin(), s.end(), s.begin(), ::tolower);
int n = s.length();
for(int i = 0; i < n; i++){
m.insert({char(s[i]),i});
}
for(char c = 'a'; c <= 'z' ; c++){
if(m.find((c)) == m.end()){
return "not pangram";
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return "pangram";
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
return 0;
}
B.
#include <bits/stdc++.h>
using namespace std;
int camelcase(string s) {
// numberofcapitalletters+1
int n = s.length();
int count = 0;
for(int i = 0; i < n; i++){
if(s[i] >= 'A' && s[i] <= 'Z'){
count++;
}
}
return count+1;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
fout.close();
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Screenshot of Outputs:
A.
B.