Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
39ea3a1
Create 994. Rotting_Oranges.cpp
sreejasaha19 Oct 4, 2022
5e629b0
combinational sum
Saikat2407 Oct 4, 2022
a5073bc
Added WordSearch Problem from Leetcode
Saikat2407 Oct 4, 2022
2b268b4
hactoberfest-2022 solution binary search leetcode
Shubham2816 Oct 4, 2022
968e0c6
Create Minimum time taken to BURN the Binary Tree from a Node
1103shambhavi Oct 5, 2022
af41282
Create All Nodes Distance K in Binary Tree
1103shambhavi Oct 5, 2022
8d941bc
Create PigLatin in Python
1103shambhavi Oct 5, 2022
482f34a
Create Remove Linked List Elements
1103shambhavi Oct 5, 2022
56730a7
added solution for 37.Sudoku Solver.cpp
vipulwakode Oct 5, 2022
9d0fae6
Merge pull request #2 from Shubham2816/newcodes
kishanrajput23 Oct 5, 2022
c97364a
Merge branch 'PawanJaiswal08:master' into newcodes
kishanrajput23 Oct 5, 2022
e0cb695
Time: 322 ms (6.31%), Space: 59.1 MB (20.30%)
PratikAgrawal02 Oct 7, 2022
5b07c2c
Create README.md
PratikAgrawal02 Oct 7, 2022
008d5d5
Richest Customer Wealth
Oct 7, 2022
e6909e5
Create level_order_tree_traversal.cpp
VIBEXD Oct 7, 2022
931aee7
Create Peak Index of an Mountain Array.cpp
shubhamsingh7272 Oct 7, 2022
3e938bc
path_sum.java
InnocentDaksh63 Oct 8, 2022
3038a1c
Merge pull request #49 from InnocentDaksh63/patch-2
PawanJaiswal08 Oct 8, 2022
984d26f
Merge pull request #48 from shubhamsingh7272/master
PawanJaiswal08 Oct 8, 2022
5478ed3
Merge pull request #47 from VIBEXD/master
PawanJaiswal08 Oct 8, 2022
83ea7e4
Merge pull request #46 from ayushi-ras/new
PawanJaiswal08 Oct 8, 2022
616eaf7
Merge pull request #45 from PratikAgrawal02/new-user
PawanJaiswal08 Oct 8, 2022
1f5f89e
Merge pull request #37 from sreejasaha19/new
PawanJaiswal08 Oct 8, 2022
a9359f0
Merge pull request #38 from Saikat2407/master
PawanJaiswal08 Oct 8, 2022
50bf774
Merge pull request #39 from 1103shambhavi/Binary-Tree-Leetcode-Solutions
PawanJaiswal08 Oct 8, 2022
be66528
Merge pull request #41 from 1103shambhavi/LINKED-LIST
PawanJaiswal08 Oct 8, 2022
414b6b8
Merge pull request #42 from vipulwakode/vip/q37
PawanJaiswal08 Oct 8, 2022
a14635e
Merge pull request #40 from 1103shambhavi/Piglatin
PawanJaiswal08 Oct 8, 2022
d942c12
Merge pull request #43 from kishanrajput23/newcodes
PawanJaiswal08 Oct 8, 2022
9ff8753
Added Search Insert Position solution
Oct 8, 2022
5a63620
mirror reflection
Anushkaa-Kashyap Oct 8, 2022
afd3708
Custom-Sort-String.cpp
SALONI-SHARMA-6 Oct 8, 2022
52af454
Add Stacks
vishweshdhoble Oct 8, 2022
659774c
Merge pull request #53 from vishweshdhoble/master
PawanJaiswal08 Oct 8, 2022
82c2e08
Merge pull request #52 from SALONI-SHARMA-6/Custom-Sort-String
PawanJaiswal08 Oct 8, 2022
ad5e5fa
Merge pull request #51 from Anushkaa-Kashyap/Mirror-Reflection
PawanJaiswal08 Oct 8, 2022
95d6d10
Merge pull request #50 from ayushi-ras/new1
PawanJaiswal08 Oct 8, 2022
d12ddd0
leetcode number of 1 bits problem
jupyterNauticals Oct 8, 2022
7d9ca73
Merge pull request #54 from jupyterNauticals/master
PawanJaiswal08 Oct 8, 2022
1c459ff
392.is-subsequence.cpp
PawanJaiswal0843 Oct 8, 2022
63d64c3
Merge pull request #60 from PawanJaiswal0843/master
PawanJaiswal08 Oct 8, 2022
2792ff0
1823.find-the-winner-of-the-circular-game.cpp
PawanJaiswal0843 Oct 8, 2022
b24236d
Merge pull request #61 from PawanJaiswal0843/master
PawanJaiswal08 Oct 8, 2022
d4d8b92
238.odd-even-linked-list.cpp
PawanJaiswal0843 Oct 8, 2022
19cf890
Merge pull request #62 from PawanJaiswal0843/master
PawanJaiswal08 Oct 8, 2022
e1bc425
3Sum_Closest.java
InnocentDaksh63 Oct 9, 2022
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
26 changes: 26 additions & 0 deletions 112. Path sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public boolean hasPathSum(TreeNode root, int targetSum) {
return solve(root,targetSum,0);
}
public boolean solve(TreeNode root, int targetSum,int currSum) {
if(root == null) return false;

//leaf node
if(root.left == null && root.right == null) {
currSum += root.val;
if(targetSum == currSum) {
return true;
}
else{
return false;
}
}


boolean left = solve(root.left,targetSum,currSum + root.val);
boolean right = solve(root.right,targetSum,currSum + root.val);

return left || right;

}
}
49 changes: 49 additions & 0 deletions 16. 3Sum Closest
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Solution {
public int threeSumClosest(int[] nums, int target) {
int n = nums.length;
int res = 0;
int m = Integer.MAX_VALUE;
Arrays.sort(nums);
for (int i = 0; i < n - 2; i++){
if (i > 0 && nums[i-1] == nums[i]){
continue;
}
if (nums[i] * 3 >= target){
int s = nums[i] + nums[i+1] + nums[i+2];
if (s - target < m){
return s;
}
break;
}
int t = nums[i] + nums[n-1] + nums[n-2];
if (t == target){
return t;
}
if (t < target){
if (t - target < m){
m = target - t;
res = t;
}
continue;
}
int a = i + 1;
int b = n - 1;
while (a < b){
t = nums[i] + nums[a] + nums[b];
if (t == target){
return t;
}
if (Math.abs(t - target) < m){
res = t;
m = Math.abs(t - target);
}
if (t > target){
b--;
} else {
a++;
}
}
}
return res;
}
}
49 changes: 49 additions & 0 deletions 1823.find-the-winner-of-the-circular-game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 1823. Find the Winner of the Circular Game
// Josephus Problem
#include<bits/stdc++.h>
using namespace std;

void solve(vector<int> &arr, int index, int k){
if(arr.size() == 1)
return;

index = (index + k) % arr.size();

arr.erase(arr.begin() + index);
index--;

solve(arr, index, k);
}

int findTheWinner(int n, int k) {
vector<int> arr;
for(int i = 1; i <= n; i++){
arr.push_back(i);
}
int index = -1;
solve(arr, index, k);
return arr[0];
}

int main(){
// Input: n = 5, k = 2
// Output: 3
// Explanation: Here are the steps of the game:
// 1) Start at friend 1.
// 2) Count 2 friends clockwise, which are friends 1 and 2.
// 3) Friend 2 leaves the circle. Next start is friend 3.
// 4) Count 2 friends clockwise, which are friends 3 and 4.
// 5) Friend 4 leaves the circle. Next start is friend 5.
// 6) Count 2 friends clockwise, which are friends 5 and 1.
// 7) Friend 1 leaves the circle. Next start is friend 3.
// 8) Count 2 friends clockwise, which are friends 3 and 5.
// 9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.
int n = 4, k = 2;
cout << findTheWinner(n,k);
return 0;
}

// for(int i = 0; i < arr.size(); i++){
// cout << arr[i] << ' ';
// }
// cout<<endl;
43 changes: 43 additions & 0 deletions 238.odd-even-linked-list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 328. Odd Even Linked List
#include <bits/stdc++.h>
using namespace std;

class ListNode {
public:
int data;
ListNode* next;

public:
ListNode(int data){
this->data = data;
this->next = NULL;
}
};

ListNode* oddEvenList(ListNode* head) {

if(head == NULL || head->next == NULL || head->next->next == NULL)
return head;

ListNode* end = head;
int count = 0;

while(end->next != NULL) {
end = end->next;
count++;
}

int counter = (count & 1) ? (count/2 + 1) : (count/2);
ListNode* temp = head;

while(counter--) {

end->next = temp->next;
temp->next = temp->next->next;
end->next->next = NULL;
temp = temp->next;
end = end->next;
}

return head;
}
52 changes: 52 additions & 0 deletions 37.Sudoku Solver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Solution
{
public:
bool check(int i, int j, int k, vector<vector<char>> &board)
{
for (int p = 0; p < 9; p++)
{
if (board[i][p] - '0' == k)
return false;
if (board[p][j] - '0' == k)
return false;
}
int x = i / 3 * 3, y = j / 3 * 3;
for (int p = x; p < x + 3; p++)
{
for (int r = y; r < y + 3; r++)
{
if (board[p][r] - '0' == k)
return false;
}
}
return true;
}
bool solve(vector<vector<char>> &board)
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (board[i][j] == '.')
{
for (int k = 1; k <= 9; k++)
{
if (check(i, j, k, board))
{
board[i][j] = '0' + k;
if (solve(board))
return true;
board[i][j] = '.';
}
}
return false;
}
}
}
return true;
}
void solveSudoku(vector<vector<char>> &board)
{
solve(board);
}
};
63 changes: 63 additions & 0 deletions 392.is-subsequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 392. Is Subsequence
#include<bits/stdc++.h>
using namespace std;

void solve(string &t, vector<string> &ans, int index, string &temp) {

if(index == t.size()) {
ans.push_back(temp);
return;
}

// exclude
solve(t, ans, index+1, temp);

// inclusion
temp.push_back(t[index]);
solve(t, ans, index+1, temp);
temp.pop_back();
}

bool isSubsequence(string s, string t) {

vector<string> ans;
string temp = "";

solve(t, ans, 0, temp);

for(int i=0; i<ans.size(); i++) {
if(ans[i] == s) {
return true;
}
}

return false;
}

bool solve2(string s, string t, int i, int j) {

if(i >= s.size())
return true;

if(i < s.size() && j >= t.size())
return false;

if(s[i] == t[j])
return solve(s, t, i+1, j+1);

else
return solve(s, t, i, j+1);
}

bool isSubsequence1(string s, string t) {
return solve2(s, t, 0, 0);
}
int main() {

string s = "abc";
string t = "ahbgdc";

cout << isSubsequence(s, t);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class Solution {
typedef long long ll;

public:
bool isPossible(vector<int> &nums)
{

map<int, int> mp, mp2;
for (ll i = 0; i < nums.size(); i++)
{
mp[nums[i]] = mp[nums[i]] + 1;
}

for (ll i = 0; i < nums.size(); i++)
{
// cout << nums[i] << " ";
if (mp2[nums[i]] && mp[nums[i]])
{
mp[nums[i]] = mp[nums[i]] - 1;
mp2[nums[i]] = mp2[nums[i]] - 1;
mp2[nums[i] + 1] = mp2[nums[i] + 1] + 1;
}
else
{
if (mp[nums[i]])
{
mp[nums[i]] = mp[nums[i]] - 1;
if (mp[nums[i] + 1])
mp[nums[i] + 1] = mp[nums[i] + 1] - 1;
else
return false;
if (mp[nums[i] + 2])
mp[nums[i] + 2] = mp[nums[i] + 2] - 1;
else
return false;
mp2[nums[i] + 3] = mp2[nums[i] + 3] + 1;
}
}
// for (ll i = 0; i < nums.size(); i++)
// {
// cout << mp[nums[i]] << " ";
// // if(mp[nums[i]])return false;
// }
}
for (ll i = 0; i < nums.size(); i++)
{
// cout<<mp[nums[i]]<<" ";
if (mp[nums[i]])
return false;
}
return true;
}
};
48 changes: 48 additions & 0 deletions 659-split-array-into-consecutive-subsequences/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<h2><a href="https://leetcode.com/problems/split-array-into-consecutive-subsequences/">659. Split Array into Consecutive Subsequences</a></h2><h3>Medium</h3><hr><div><p>You are given an integer array <code>nums</code> that is <strong>sorted in non-decreasing order</strong>.</p>

<p>Determine if it is possible to split <code>nums</code> into <strong>one or more subsequences</strong> such that <strong>both</strong> of the following conditions are true:</p>

<ul>
<li>Each subsequence is a <strong>consecutive increasing sequence</strong> (i.e. each integer is <strong>exactly one</strong> more than the previous integer).</li>
<li>All subsequences have a length of <code>3</code><strong> or more</strong>.</li>
</ul>

<p>Return <code>true</code><em> if you can split </em><code>nums</code><em> according to the above conditions, or </em><code>false</code><em> otherwise</em>.</p>

<p>A <strong>subsequence</strong> of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., <code>[1,3,5]</code> is a subsequence of <code>[<u>1</u>,2,<u>3</u>,4,<u>5</u>]</code> while <code>[1,3,2]</code> is not).</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre><strong>Input:</strong> nums = [1,2,3,3,4,5]
<strong>Output:</strong> true
<strong>Explanation:</strong> nums can be split into the following subsequences:
[<strong><u>1</u></strong>,<strong><u>2</u></strong>,<strong><u>3</u></strong>,3,4,5] --&gt; 1, 2, 3
[1,2,3,<strong><u>3</u></strong>,<strong><u>4</u></strong>,<strong><u>5</u></strong>] --&gt; 3, 4, 5
</pre>

<p><strong>Example 2:</strong></p>

<pre><strong>Input:</strong> nums = [1,2,3,3,4,4,5,5]
<strong>Output:</strong> true
<strong>Explanation:</strong> nums can be split into the following subsequences:
[<strong><u>1</u></strong>,<strong><u>2</u></strong>,<strong><u>3</u></strong>,3,<strong><u>4</u></strong>,4,<strong><u>5</u></strong>,5] --&gt; 1, 2, 3, 4, 5
[1,2,3,<strong><u>3</u></strong>,4,<strong><u>4</u></strong>,5,<strong><u>5</u></strong>] --&gt; 3, 4, 5
</pre>

<p><strong>Example 3:</strong></p>

<pre><strong>Input:</strong> nums = [1,2,3,4,4,5]
<strong>Output:</strong> false
<strong>Explanation:</strong> It is impossible to split nums into consecutive increasing subsequences of length 3 or more.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
<li><code>-1000 &lt;= nums[i] &lt;= 1000</code></li>
<li><code>nums</code> is sorted in <strong>non-decreasing</strong> order.</li>
</ul>
</div>
Loading