Skip to content

Create Count of Subarrays in an Array #204

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

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
d5ab1dd
Add maximum value of Ordered Triplets
Dipanita45 Apr 14, 2025
797743f
U
Dipanita45 Apr 14, 2025
3cabcce
Change
Dipanita45 Apr 15, 2025
0390b5e
Combination_Sum
Dipanita45 Apr 15, 2025
3c135ec
Create Count of Good Subarrays.java
Dipanita45 Apr 16, 2025
56f1e4a
Merge pull request #2 from Dipanita45/Be
Dipanita45 Apr 16, 2025
1aa98be
Add Create Equal and Divisible in an Array
Dipanita45 Apr 17, 2025
016f15c
Update
Dipanita45 Apr 21, 2025
5e4c852
u
Dipanita45 Apr 21, 2025
c9f3135
Update
Dipanita45 Apr 22, 2025
a3f2228
Change
Dipanita45 Apr 23, 2025
ccb4566
Merge pull request #4 from Dipanita45/bas
Dipanita45 Apr 23, 2025
3fbaf29
Update
Dipanita45 Apr 24, 2025
3d6dfae
Merge branch 'master' into bashh
Dipanita45 Apr 25, 2025
3545219
Merge pull request #5 from Dipanita45/bashh
Dipanita45 Apr 25, 2025
2856057
Merge pull request #6 from Dipanita45/master
Dipanita45 Apr 28, 2025
d35b06f
Merge pull request #7 from Dipanita45/master
Dipanita45 Apr 29, 2025
bdd87ff
Merge pull request #8 from Dipanita45/dev
Dipanita45 Apr 30, 2025
f3a1508
Merge pull request #9 from Dipanita45/bashd
Dipanita45 May 1, 2025
95e18d7
Merge branch 'kamyu104:master' into master
Dipanita45 May 3, 2025
44dc2ab
Create Count of Subarray with Score less than k.java
Dipanita45 May 3, 2025
957c010
Domino
Dipanita45 May 5, 2025
d587bff
Merge branch 'master' into batchh
Dipanita45 May 5, 2025
790b420
Domino and Tromino Tiling .java
Dipanita45 May 5, 2025
c049719
Create
Dipanita45 May 6, 2025
dd4c0e8
Create Build Array from Permutation.java
Dipanita45 May 6, 2025
577aa59
Changes
Dipanita45 May 7, 2025
48ff6a2
Create Find Minimum time to reach the last room I.java
Dipanita45 May 7, 2025
df698de
Create
Dipanita45 May 8, 2025
c71b464
Create Minimum Time to reach the last room II.java
Dipanita45 May 8, 2025
c3fb29a
Create Count Number of Balanced Permutation.java
Dipanita45 May 9, 2025
0cf4cf6
Create Count of Balanced Permutation.java
Dipanita45 May 9, 2025
077559e
Minimum Equal sum of Two Array After Replacing Zeroes.java
Dipanita45 May 10, 2025
8608016
Minimum Equal sum of Two Array After Replacing Zeroes.java
Dipanita45 May 10, 2025
d3503e9
Create
Dipanita45 May 12, 2025
b96b15d
Create Three Consecutive Odds.java
Dipanita45 May 12, 2025
0455222
Create Length of the String After Transformation I.java
Dipanita45 May 13, 2025
d8d8596
Create Length of the String After Transformation I.java
Dipanita45 May 13, 2025
7083394
Create Length oof the String After Transformation II.java
Dipanita45 May 14, 2025
0b312a3
Merge pull request #20 from Dipanita45/patch-1
Dipanita45 May 14, 2025
9c03d55
Create Longest Unequal Sequence I .java
Dipanita45 May 15, 2025
c37f5ba
Create Longest Unequal Sequence I .java
Dipanita45 May 15, 2025
c9f586d
Longest Unequal Adjacent Groups Sequence II.java
Dipanita45 May 16, 2025
669a16c
Longest Unequal Adjacent Groups Sequence II.java
Dipanita45 May 16, 2025
2e89888
Sort Colors
Dipanita45 May 17, 2025
da39a92
Sort Colors
Dipanita45 May 17, 2025
2993d4a
Create Painting the Grid with N different Colors.java
Dipanita45 May 18, 2025
048a8bb
Create Painting the Grid with N different Colors.java
Dipanita45 May 18, 2025
1dcec10
Create Type of Triangle.java
Dipanita45 May 19, 2025
00a2a6c
Create Type of Triangle.java
Dipanita45 May 19, 2025
ec18705
Zero Array Transformation I
Dipanita45 May 20, 2025
b871e35
Create Zero Array Transformation I.java
Dipanita45 May 20, 2025
f0cff59
Set Zeroes Matrix
Dipanita45 May 21, 2025
ea7840c
Create
Dipanita45 May 21, 2025
0961185
Create Set Zeroes Matrix.java
Dipanita45 May 21, 2025
4029ede
Create Zero Array Transformation.java
Dipanita45 May 22, 2025
761d45f
Zero Array Transformation III
Dipanita45 May 22, 2025
51c20db
Create Zero Array Transformation III.java
Dipanita45 May 22, 2025
625e176
Create Valid parenthesis.java
Dipanita45 May 22, 2025
6cba66e
Merge pull request #29 from Dipanita45/Dipanita45-patch-1
Dipanita45 May 22, 2025
8e676f9
Create Reverse Integer.cpp
Dipanita45 May 23, 2025
58cabf5
Merge pull request #30 from Dipanita45/Dipanita45-patch-2
Dipanita45 May 23, 2025
a0f7c65
Create Find Words Containing Character.java
Dipanita45 May 24, 2025
8df9ee3
Create Find Words Containing Character.java
Dipanita45 May 24, 2025
c4dc37a
Create Longest palindrome by concatenating two words.java
Dipanita45 May 25, 2025
93dc11b
Merge pull request #32 from Dipanita45/Dipanita45-patch-4
Dipanita45 May 25, 2025
17066bc
Create Add Two Numbers.java
Dipanita45 May 26, 2025
f06e75a
Merge pull request #33 from Dipanita45/Dipanita45-patch-5
Dipanita45 May 26, 2025
037cd67
Create Divisible And Non-divisible Sum Differences.java
Dipanita45 May 27, 2025
f3573fc
Create Divisible And Non-divisible Sum Differences.java
Dipanita45 May 27, 2025
c6a57ba
Create Reverse Integer . java
Dipanita45 May 28, 2025
ac9b7d0
Merge pull request #35 from Dipanita45/Dipanita45-patch-7
Dipanita45 May 28, 2025
4cfbb7a
Create Palindrome Number.cpp
Dipanita45 May 29, 2025
36e0bda
Merge pull request #36 from Dipanita45/Dipanita45-patch-8
Dipanita45 May 29, 2025
f10f5d7
Create Longest Palindromic Substring.java
Dipanita45 May 30, 2025
7c73ffe
Merge pull request #37 from Dipanita45/Dipanita45-patch-9
Dipanita45 May 30, 2025
973f390
Create Snakes And Ladders.java
Dipanita45 May 31, 2025
6867fd1
Merge pull request #38 from Dipanita45/Dipanita45-patch-10
Dipanita45 May 31, 2025
875a93c
Create Distribute Candies Among Children II .java
Dipanita45 Jun 1, 2025
42bdc85
Merge pull request #39 from Dipanita45/Dipanita45-patch-11
Dipanita45 Jun 1, 2025
4c13f67
Create Candy.java
Dipanita45 Jun 2, 2025
f48c37a
Create Zigzag Conversion
Dipanita45 Jun 2, 2025
5ba9dfb
Merge pull request #40 from Dipanita45/Dipanita45-patch-12
Dipanita45 Jun 2, 2025
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
22 changes: 22 additions & 0 deletions Add Two Numbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode dummy = new ListNode();
ListNode cur=dummy;
int carry=0;
while(l1!=null || l2!=null || carry!=0){
int sum=carry;
if(l1!=null){
sum +=l1.val;
l1=l1.next;
}
if (l2 != null) {
sum += l2.val;
l2 = l2.next;
}
carry = sum / 10;
cur.next = new ListNode(sum % 10);
cur = cur.next;
}
return dummy.next;
}
}
49 changes: 49 additions & 0 deletions C++/Combination Sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include<vector>
#include<stdio.h>

class Solution {

public:

vector<vector<int>> combinationSum(vector<int>& candidates, int target) {

vector<vector<int>> res;

vector<int> comb;

makeCombination(candidates, target, 0, comb, 0, res);

return res;

}

private:

void makeCombination(std::vector<int>& candidates, int target, int idx, vector<int>& comb, int total, vector<vector<int>>& res) {

if (total == target) {

res.push_back(comb);

return;

}

if (total > target || idx >= candidates.size()) {

return;

}

comb.push_back(candidates[idx]);

makeCombination(candidates, target, idx, comb, total + candidates[idx], res);

comb.pop_back();

makeCombination(candidates, target, idx + 1, comb, total, res);

}

};

17 changes: 17 additions & 0 deletions C++/Diameter of a Binary Tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
int ans=0;
int height(TreeNode* root){
if(root==NULL){
return 0;
}
int leftHt= height(root->left);
int rightHt= height(root->right);
ans=max(leftHt+rightHt,ans);
return max(leftHt,rightHt)+1;
}
int diameterOfBinaryTree(TreeNode* root) {
height(root);
return ans;
}
};
32 changes: 32 additions & 0 deletions C++/Lowest Common Ancestor of a Binary Tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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:
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
if(root==NULL){
return NULL;
}
if(root->val==p->val || root->val==q->val){
return root;
}
TreeNode* leftLCA=lowestCommonAncestor(root->left,p,q);
TreeNode* rightLCA=lowestCommonAncestor(root->right,p,q);
if(leftLCA && rightLCA)
{
return root;
}
else if(leftLCA!=NULL){
return leftLCA;
}
else{
return rightLCA;
}
}
};
25 changes: 25 additions & 0 deletions C++/Palindrome Number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
int reverse(int x){
int revNum=0;
while(x!=0)
{
int dig=x%10;
if(revNum>INT_MAX/10 || revNum<INT_MIN/10)
{
return 0;
}
revNum=revNum*10+dig;
x=x/10;
}
return revNum;
}
bool isPalindrome(int x) {
if(x<0)
{
return false;
}
int revNum=reverse(x);
return x==revNum;
}
};
33 changes: 33 additions & 0 deletions C++/Zigzag Conversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


class Solution {
public:

string convert(string s, int numRows) {

if(numRows <= 1) return s;

vector<string>v(numRows, "");

int j = 0, dir = -1;

for(int i = 0; i < s.length(); i++)
{

if(j == numRows - 1 || j == 0) dir *= (-1);

v[j] += s[i];

if(dir == 1) j++;

else j--;
}

string res;

for(auto &it : v) res += it;

return res;

}
};
69 changes: 69 additions & 0 deletions Count Number of Balanced Permutation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Solution {

private static final long MOD = 1_000_000_007;

public int countBalancedPermutations(String num) {
int tot = 0, n = num.length();
int[] cnt = new int[10];
for (char ch : num.toCharArray()) {
int d = ch - '0';
cnt[d]++;
tot += d;
}
if (tot % 2 != 0) {
return 0;
}

int target = tot / 2;
int maxOdd = (n + 1) / 2;
long[][] comb = new long[maxOdd + 1][maxOdd + 1];
long[][] f = new long[target + 1][maxOdd + 1];

for (int i = 0; i <= maxOdd; i++) {
comb[i][i] = comb[i][0] = 1;
for (int j = 1; j < i; j++) {
comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD;
}
}

f[0][0] = 1;
int psum = 0, totSum = 0;
for (int i = 0; i <= 9; i++) {
/* Sum of the number of the first i digits */
psum += cnt[i];
/* Sum of the first i numbers */
totSum += i * cnt[i];
for (
int oddCnt = Math.min(psum, maxOdd);
oddCnt >= Math.max(0, psum - (n - maxOdd));
oddCnt--
) {
/* The number of bits that need to be filled in even numbered positions */
int evenCnt = psum - oddCnt;
for (
int curr = Math.min(totSum, target);
curr >= Math.max(0, totSum - target);
curr--
) {
long res = 0;
for (
int j = Math.max(0, cnt[i] - evenCnt);
j <= Math.min(cnt[i], oddCnt) && i * j <= curr;
j++
) {
/* The current digit is filled with j positions at odd positions, and cnt[i] - j positions at even positions */
long ways =
(comb[oddCnt][j] * comb[evenCnt][cnt[i] - j]) % MOD;
res =
(res +
((ways * f[curr - i * j][oddCnt - j]) % MOD)) %
MOD;
}
f[curr][oddCnt] = res % MOD;
}
}
}

return (int) f[target][maxOdd];
}
}
13 changes: 13 additions & 0 deletions Divisible And Non-divisible Sum Differences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public int differenceOfSums(int n, int m) {
int ans=0;
for(int i=1;i<=n;i++){
if(i % m ==0){
ans-=i;
}else{
ans+=i;
}
}
return ans;
}
}
13 changes: 13 additions & 0 deletions Find Words Containing Character.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public List<Integer> findWordsContaining(String[] words, char x) {
List<Integer> res=new ArrayList<>();
int n=words.length;
for(int i=0;i<n;i++)
{
if(words[i].indexOf(x)!=-1){
res.add(i);
}
}
return res;
}
}
14 changes: 14 additions & 0 deletions Java/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>


<id>1744612223460</id>

<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions Java/Build Array from Permutation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {

public int[] buildArray(int[] nums) {
int n = nums.length;
int[] ans = new int[n];
for (int i = 0; i < n; ++i) {
ans[i] = nums[nums[i]];
}
return ans;
}
}
29 changes: 29 additions & 0 deletions Java/Candy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public int candy(int[] ratings) {
int n = ratings.length;
int[] cand = new int[n];
Arrays.fill(cand, 1); // Step 1: Each child gets at least one candy

// Step 2: Left to right pass
for (int i = 1; i < n; i++) {
if (ratings[i] > ratings[i - 1]) {
cand[i] = cand[i - 1] + 1;
}
}

// Step 3: Right to left pass
for (int i = n - 2; i >= 0; i--) {
if (ratings[i] > ratings[i + 1] && cand[i] <= cand[i + 1]) {
cand[i] = cand[i + 1] + 1;
}
}

// Step 4: Sum all candies
int ans = 0;
for (int c : cand) {
ans += c;
}

return ans;
}
}
17 changes: 17 additions & 0 deletions Java/Count Equal and Divisible in an Array.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public int countPairs(int[] nums, int k) {
int n=nums.length;
int res=0;
for(int i=0;i<n-1;++i)
{
for(int j=i+1;j<n;++j)
{
if((i*j)%k==0 && nums[i]==nums[j])
{
++res;
}
}
}
return res;
}
}
19 changes: 19 additions & 0 deletions Java/Count Hidden Sequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Solution {
public int numberOfArrays(int[] differences, int lower, int upper) {
int n = differences.length;
int prefix = 0;
int min = 0;
int max = 0;
int diff = upper-lower;

for(int i = 0;i<n;i++){
prefix = prefix + differences[i];
min = Math.min(min,prefix);
max = Math.max(max,prefix);
if(max-min > diff) return 0;
}
return (diff) - (max -min) +1;
}
}


Loading