Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added adobe problems #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions company/adobe/chocolate_wrapper.cpp
@@ -0,0 +1,49 @@
// Recursive C++ program to find maximum
// number of chocolates
#include <iostream>
using namespace std;

// Returns number of chocolates we can
// have from given number of chocolates
// and number of wrappers required to
// get a chocolate.
int countRec(int choc, int wrap)
{
// If number of chocolates is less than
// number of wrappers required.
if (choc < wrap)
return 0;

// We can immediatly get newChoc using
// wrappers of choc.
int newChoc = choc/wrap;

// Now we have "newChoc + choc%wrap" wrappers.
return newChoc + countRec(newChoc + choc%wrap,
wrap);
}

// Returns maximum number of chocolates we can eat
// with given money, price of chocolate and number
// of wrappers required to get a chocolate.
int countMaxChoco(int money, int price, int wrap)
{
// We can directly buy below number of chocolates
int choc = money/price;

// countRec returns number of chocolates we can
// have from given number of chocolates
return choc + countRec(choc, wrap);
}

// Driver code
int main()
{
int money = 15 ; // total money
int price = 1; // cost of each candy
int wrap = 3 ; // no of wrappers needs to be
// exchanged for one chocolate.

cout << countMaxChoco(money, price, wrap);
return 0;
}
36 changes: 36 additions & 0 deletions company/adobe/rightSideView_binarytree.cpp
@@ -0,0 +1,36 @@
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
unordered_map<int, int>mp;
void rightSideViewH(TreeNode* root, int k = 0) {

if(root->left){
rightSideViewH(root->left, k+1);
mp[k] = root->left->val;
}if(root->right){
rightSideViewH(root->right, k+1);
mp[k] = root->right->val;
}
}
vector<int> rightSideView(TreeNode* root){
vector<int>v;

if(root == NULL)
return v;

v.push_back(root->val);
rightSideViewH(root);
for(auto it = 0; it < mp.size(); it++){
v.push_back(mp[it]);
}
return v;
}
};