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

Create integer.cpp #196

Open
wants to merge 30 commits into
base: revert-179-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0260770
added leetcode dsa questions
srdhal Oct 21, 2022
3214142
Revert "Create FractionalKnapsack.java"
prashantkalokhe Oct 21, 2022
b2807d3
Revert "Added LeetCode DSA problem"
prashantkalokhe Oct 21, 2022
2f821c3
Revert "Simple Calculator"
prashantkalokhe Oct 21, 2022
0faf806
Merge pull request #184 from prashantkalokhe/revert-175-jainshubham76…
prashantkalokhe Oct 21, 2022
4fa2128
Merge pull request #185 from prashantkalokhe/revert-182-patch-1
prashantkalokhe Oct 21, 2022
b69608b
Merge pull request #186 from prashantkalokhe/revert-181-patch-7
prashantkalokhe Oct 21, 2022
8993d4b
Merge pull request #187 from prashantkalokhe/revert-179-main
prashantkalokhe Oct 21, 2022
ac9e100
Rename README.md to README.me1
prashantkalokhe Oct 21, 2022
e9001d9
added Longest Substring
DevanshUpadhyay26 Oct 21, 2022
8f1c98b
HouseRobber Problem in Java
bishtkiran Oct 21, 2022
0fd50f1
Update README.me
prashantkalokhe Oct 21, 2022
40986ce
Hacktoberfest2022
dipesh88 Oct 21, 2022
ff9fd3e
Create reverse_integer.cpp
pathakdeepanshu Oct 22, 2022
3ec93e2
Merge pull request #191 from dipesh88/main
prashantkalokhe Oct 22, 2022
2583e34
Merge pull request #192 from pathakdeepanshu/patch-1
prashantkalokhe Oct 22, 2022
e3d4bdc
Merge pull request #190 from bishtkiran/patch-1
prashantkalokhe Oct 22, 2022
7116f33
Merge pull request #183 from srdhal/dsa
prashantkalokhe Oct 22, 2022
2a5951d
Merge pull request #189 from DevanshUpadhyay26/main
prashantkalokhe Oct 22, 2022
a8b4133
Rename README.me1 to README.md
prashantkalokhe Oct 22, 2022
1f8d4e0
dsa-recursion.java
suryakantdubalgundeoutlook Oct 22, 2022
34dc741
Add files via upload
jairam15 Oct 27, 2022
4b025b9
Merge pull request #199 from jairam15/main
prashantkalokhe Oct 27, 2022
83cc6f3
Shortest Path In a Maze
rokingshubham1 Oct 27, 2022
0af1ac0
Linked List
rokingshubham1 Oct 27, 2022
0cd6394
Merge pull request #201 from rokingshubham1/main
prashantkalokhe Oct 28, 2022
f0e1a5d
Update README.md
prashantkalokhe Oct 28, 2022
51e23ea
Create FibonacciNumberFunction.java
amisha64 Oct 29, 2022
c794d3f
Merge pull request #203 from amisha64/main
prashantkalokhe Oct 30, 2022
bba5277
Merge pull request #193 from suryakantdubalgundeoutlook/main
prashantkalokhe Jan 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions C++_DSA/BinaryTreeInorderTraversal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*

Binary Tree Inorder Traversal

Given the root of a binary tree, return the inorder traversal of its nodes' values.



Input: root = [1,null,2,3]
Output: [1,3,2]
Example 2:

Input: root = []
Output: []
Example 3:

Input: root = [1]
Output: [1]


Constraints:

The number of nodes in the tree is in the range [0, 100].
-100 <= Node.val <= 100


*/


/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:




vector<int> inorderTraversal(TreeNode* root) {
vector<int> v;

stack<TreeNode*> s;


while(root || !s.empty()){

while(root){
s.push(root);
root=root->left;
}
root=s.top();
s.pop();
v.push_back(root->val);
root=root->right;
}


return v;
}
};
69 changes: 69 additions & 0 deletions C++_DSA/BinaryTreeMinimumDepth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*

Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Note: A leaf is a node with no children.


Input: root = [3,9,20,null,null,15,7]
Output: 2
Example 2:

Input: root = [2,null,3,null,4,null,5,null,6]
Output: 5


Constraints:

The number of nodes in the tree is in the range [0, 105].
-1000 <= Node.val <= 1000

*/


/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
int minDepth(TreeNode* root) {
int c=0;
if(!root) return c;

queue<TreeNode*> q;

q.push(root);

while(!q.empty()){

int x=q.size();
c++;
while(x){
TreeNode *t=q.front();
q.pop();
if(t->left ==nullptr && t->right ==nullptr){
return c;
}
if(t->left) q.push(t->left);
if(t->right) q.push(t->right);
x--;
}


}

return c;
}
};
16 changes: 16 additions & 0 deletions FibonacciNumberFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//Using Dynamic Programming
static int fib(int n)
{
int f[] = new int[n+2]; // 1 extra to handle case, n = 0
int i;

f[0] = 0;
f[1] = 1;

for (i = 2; i <= n; i++)
{
f[i] = f[i-1] + f[i-2];
}

return f[n];
}
33 changes: 33 additions & 0 deletions Java_DSA/DSA-Recursion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class RecursionDemo {
public static void main(String[] args){
RecursionDemo recursionDemo = new RecursionDemo();
int n = 5;
System.out.println(Factorial of + n +
+ recursionDemo.factorial(n));
System.out.print(Fibbonacci of + n + );
for(int i=0;in;i++){
System.out.print(recursionDemo.fibbonacci(i) + );
}
}

private int factorial(int n){
base case
if(n == 0){
return 1;
}else{
return n factorial(n-1);
}
}

private int fibbonacci(int n){
if(n ==0){
return 0;
}
else if(n==1){
return 1;
}
else {
return (fibbonacci(n-1) + fibbonacci(n-2));
}
}
}
88 changes: 0 additions & 88 deletions Java_DSA/FractionalKnapsack.java

This file was deleted.

30 changes: 30 additions & 0 deletions Java_DSA/HouseRobber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* You are a professional robber planning to rob houses along a street.
Each house has acertain amount of monet stashed.
The onlt constraint stopping you for robbing each of them is that each house have security systems connected and it will automatically contact the police
if two ajacent houses were broken into on the same night.
Considering the constarints determine the maximum amount of money you can rob tonight without alerting the police.
*/

public class HouseRobber{
public static void main(String[] args) {
int[] arr = {2,45,8,7,98,24};
int maxAmount = robHouse(arr);
System.out.println("Maximum amount that can be robbed : "+ maxAmount);
}

static int robHouse(int[] arr){
int prev = arr[0], curr = Math.max(arr[0], arr[1]);

for(int i =2; i< arr.length; i++){
int temp = curr;
curr = Math.max(prev + arr[i], curr);
prev = temp;
}
return curr;
}
}




//prints:- Maximum amount that can be robbed : 143
23 changes: 0 additions & 23 deletions Java_DSA/LeetCode_Same_Tree.java

This file was deleted.

Loading