Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
66f4803
Square Submatrices with all Ones
swamini-jadhav Oct 22, 2025
23ef99b
Add DFS implementation in Dfs.java
SuramyaRanjan Oct 22, 2025
a916c37
Implement binary search algorithm in Python
Shristi15-web Oct 22, 2025
ab81cce
Add movie recommendation system using Random Forest
Symbiote07 Oct 22, 2025
d980661
Find the City With the Smallest Number of Neighbors at a Threshold Di…
SahuUsha Oct 22, 2025
8fd9867
Unique Path using DP
SahuUsha Oct 22, 2025
d193263
delete
SahuUsha Oct 22, 2025
b719352
Unique Path-ii using Dp
SahuUsha Oct 22, 2025
5464662
delete
SahuUsha Oct 22, 2025
bcdee0e
Unique Path-ii using Dp
SahuUsha Oct 22, 2025
694989e
Merge branch 'ghostmkg:develop' into develop
SahuUsha Oct 22, 2025
888c643
Create RadixSort.java
sahilsharma17 Oct 22, 2025
d1ea327
Merge pull request #1 from ghostmkg/main
Anusha5D Oct 22, 2025
578bb45
added new file
Anusha5D Oct 22, 2025
cbf415d
Merge pull request #1110 from swamini-jadhav/feature-2
ghostmkg Oct 23, 2025
ba7641a
Merge pull request #1111 from SuramyaRanjan/main
ghostmkg Oct 23, 2025
0861975
Merge pull request #1114 from laxmiamrutapadhi/main
ghostmkg Oct 23, 2025
e773106
Merge pull request #1119 from Shristi15-web/main
ghostmkg Oct 23, 2025
cc44883
Merge pull request #1120 from Symbiote07/patch-1
ghostmkg Oct 23, 2025
e9032a9
Merge pull request #1122 from SahuUsha/develop
ghostmkg Oct 23, 2025
46a0d60
Merge pull request #1125 from sahilsharma17/main
ghostmkg Oct 23, 2025
e839267
Merge pull request #1127 from Anusha5D/bouquets_cpp
ghostmkg Oct 23, 2025
8f32be1
CSES Problem Solution in C++
purrvax Oct 23, 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
53 changes: 53 additions & 0 deletions Dfs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.util.*;

public class Dfs {
private int V; // Number of vertices
private LinkedList<Integer>[] adj; // Adjacency lists

// Constructor
public Dfs(int v) {
V = v;
adj = new LinkedList[v];
for (int i = 0; i < v; i++) {
adj[i] = new LinkedList<>();
}
}

// Add an edge to the graph
public void addEdge(int v, int w) {
adj[v].add(w);
}

// DFS traversal from a given source
public void DFS(int start) {
boolean[] visited = new boolean[V];
dfsUtil(start, visited);
}

// Utility function for DFS
private void dfsUtil(int v, boolean[] visited) {
visited[v] = true;
System.out.print(v + " ");

for (int n : adj[v]) {
if (!visited[n]) {
dfsUtil(n, visited);
}
}
}

// Sample usage
public static void main(String[] args) {
Dfs graph = new Dfs(4);

graph.addEdge(0, 1);
graph.addEdge(0, 2);
graph.addEdge(1, 2);
graph.addEdge(2, 0);
graph.addEdge(2, 3);
graph.addEdge(3, 3);

System.out.println("DFS starting from vertex 2:");
graph.DFS(2);
}
}
56 changes: 56 additions & 0 deletions RadixSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* RadixSort.java
*
* Description:
* Radix Sort is a non-comparison sorting algorithm that sorts numbers
* digit by digit starting from the least significant digit (LSD) to
* the most significant digit (MSD). It uses Counting Sort as a subroutine.
*
* Time Complexity: O(n * k) where k is the number of digits
* Space Complexity: O(n + k)
* Stable: Yes
*/

public class RadixSort {
public static void radixSort(int[] arr) {
if (arr.length == 0) return;

// Find the maximum number to know number of digits
int max = arr[0];
for (int num : arr) {
if (num > max) max = num;
}

// Apply counting sort for every digit (exp = 1, 10, 100, ...)
for (int exp = 1; max / exp > 0; exp *= 10) {
countingSortByDigit(arr, exp);
}
}

private static void countingSortByDigit(int[] arr, int exp) {
int n = arr.length;
int[] output = new int[n];
int[] count = new int[10]; // Digits 0–9

// Store count of occurrences for each digit
for (int num : arr) {
int index = (num / exp) % 10;
count[index]++;
}

// Cumulative count
for (int i = 1; i < 10; i++) {
count[i] += count[i - 1];
}

// Build the output array (traverse backwards for stability)
for (int i = n - 1; i >= 0; i--) {
int index = (arr[i] / exp) % 10;
output[count[index] - 1] = arr[i];
count[index]--;
}

// Copy output to original array
System.arraycopy(output, 0, arr, 0, n);
}
}
16 changes: 9 additions & 7 deletions SQL/DepartmentTopThreeSalaries.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
SELECT Department, Employee, Salary
FROM (
SELECT d.Name AS Department,
e.Name AS Employee,
e.Salary,
DENSE_RANK() OVER (PARTITION BY d.Id ORDER BY e.Salary DESC) AS rnk
WITH RankedSalaries AS (
SELECT
d.Name AS Department,
e.Name AS Employee,
e.Salary,
DENSE_RANK() OVER (PARTITION BY d.Id ORDER BY e.Salary DESC) AS rnk
FROM Employee e
JOIN Department d ON e.DepartmentId = d.Id
) ranked
)
SELECT Department, Employee, Salary
FROM RankedSalaries
WHERE rnk <= 3;
47 changes: 47 additions & 0 deletions Square_SubMat_With_Ones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import List

class Solution:
def countSquares(self, matrix: List[List[int]]) -> int:
# Get number of rows and columns
r = len(matrix)
c = len(matrix[0])

# dp[i][j] will store the size of the largest square
# whose bottom-right corner is at cell (i, j)
dp = [[0] * c for _ in range(r)]

count = 0 # To store total number of square submatrices

# Initialize first row
# Each 1 in the first row forms a 1x1 square
for j in range(c):
if matrix[0][j] == 1:
dp[0][j] = 1
count += 1

# Initialize first column
# Each 1 in the first column forms a 1x1 square
for i in range(1, r):
if matrix[i][0] == 1:
dp[i][0] = 1
count += 1

# Fill the dp table for the rest of the matrix
for i in range(1, r):
for j in range(1, c):
# If the cell is 0, no square can end here
if matrix[i][j] == 0:
continue
# If the cell is 1, find the smallest neighboring square
# and extend it by 1 to form a bigger square
elif dp[i-1][j] == 0 or dp[i-1][j-1] == 0 or dp[i][j-1] == 0:
dp[i][j] = 1 # Only a 1x1 square possible
else:
# Minimum of top, left, and top-left + 1
dp[i][j] = min(dp[i-1][j], dp[i-1][j-1], dp[i][j-1]) + 1

# Add the number of squares ending at (i, j)
count += dp[i][j]

# Return total count of all square submatrices with all 1s
return count
67 changes: 67 additions & 0 deletions c++/Algorithm/Bucket Sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <bits/stdc++.h>
using namespace std;
int findMax(int arr[], int n)
{
int i,max=arr[0],cnt=0;
for(i=1;i<n;i++)
{
if(arr[i]>max)
max=arr[i];
}
while(max>0)
{
cnt++;
max=max/10;
}

return cnt;
}

void bucketSort(int arr[],int *bucket[],int n)
{
static int i,j[10],k,l,d=1;
int c;
c=findMax(arr,n);

for(int m=0;m<c;m++)
{
for(i=0;i<10;i++)
j[i]=0;
for(i=0;i<n;i++)
{
k=(arr[i]/d)%10;
bucket[k][j[k]]=arr[i];
j[k]++;
}

l=0;
for(i=0;i<10;i++)
{
for(k=0;k<j[i];k++)
{
arr[l]=bucket[i][k];
l++;
}
}
d*=10;
}
}
int main()
{
int n,*arr,i;
int *bucket[10];
cout<<"Enter no of element : ";
cin>>n;
arr=new int[n+1];
for(i=0;i<10;i++)
bucket[i]=new int[n];
cout<<"Enter array element : ";
for(i=0;i<n;i++)
cin>>arr[i];
bucketSort(arr,bucket,n);

cout<<"Sorted array : ";
for(i=0;i<n;i++)
cout<<arr[i]<<" ";
return 0;
}
69 changes: 69 additions & 0 deletions c++/Binary Search/min_days_for_m_bouquets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
bool possible(vector<int>& arr, int day, int n, int m, int k) {
int count = 0;
int no_of_bouquet = 0;
for (int i = 0; i < n; i++) {
if (arr[i] <= day) {
count++;
} else {
no_of_bouquet += (count / k);
count = 0;
}
}
no_of_bouquet += (count / k);
return no_of_bouquet >= m;
}

int minDays(vector<int>& bloomDay, int m, int k) {
int n = bloomDay.size();
int minday = INT_MAX;
int maxday = INT_MIN;
for (int i = 0; i < n; i++) {
minday = min(minday, bloomDay[i]);
maxday = max(maxday, bloomDay[i]);
}

// if total flowers < total needed flowers
if (n < (long long)m * k) return -1;

int low = minday;
int high = maxday;
int ans = maxday;

while (low <= high) {
int mid = low + (high - low) / 2;
if (possible(bloomDay, mid, n, m, k)) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
};

int main() {
int n, m, k;
cout << "Enter number of flowers (n): ";
cin >> n;
cout << "Enter number of bouquets (m): ";
cin >> m;
cout << "Enter flowers per bouquet (k): ";
cin >> k;

vector<int> bloomDay(n);
cout << "Enter bloom days of each flower: ";
for (int i = 0; i < n; i++) {
cin >> bloomDay[i];
}

Solution sol;
int result = sol.minDays(bloomDay, m, k);
cout << "Minimum number of days required: " << result << endl;
return 0;
}
16 changes: 16 additions & 0 deletions c++/CSES_Introductory_Problem/Missing_Number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;

int main(){
long long n;
cin >> n;
vector<long long> a(n - 1);
long long ans = 0;
for(long long i = 0; i < n - 1; i++){
cin >> a[i];
ans += a[i];
}
long long sum = (n * (n + 1)) / 2;
cout << sum - ans << endl;
return 0;
}
19 changes: 19 additions & 0 deletions c++/CSES_Introductory_Problem/Permutation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
if (n == 3 || n == 2) {
cout << "NO SOLUTION";
} else {
for (int i = 1; i <= n; i++) {
if (i % 2 == 0) cout << i << " ";
}
for (int i = 1; i <= n; i++) {
if (i % 2 != 0) cout << i << " ";
}
}
return 0;
}
17 changes: 17 additions & 0 deletions c++/CSES_Introductory_Problem/Weird_Algorithm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
using namespace std;

int main(){
long long n;
cin>>n;
cout << n << " ";
while(n != 1){
if(n % 2 == 0){
n = n/2;
}else{
n = n*3 + 1;
}
cout << n << " ";
}
return 0;
}
Loading