forked from SamirPaulb/DSAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2412832
commit 073c50a
Showing
185 changed files
with
174 additions
and
173 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 27 additions & 27 deletions
54
...PROBLEM-SOLVING/48.Rotate Image-Matrix.py → ...PROBLEM-SOLVING/48.Rotate Image-Matrix.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
# https://www.youtube.com/watch?v=Y72QeX0Efxw | ||
''' | ||
First Transpose(flip matrix over its diagonal) the matrix then rotate every rows | ||
[[1,2,3], [[1,4,7], [[7,4,1], | ||
[4,5,6], =>Transpose=> [2,5,8], =>Rotate rows=> [8,5,2], | ||
[7,8,9]] [3,6,9]] [9,6,3]] | ||
''' | ||
class Solution: | ||
def rotate(self, matrix: List[List[int]]) -> None: | ||
#Transpose | ||
for i in range(len(matrix)): | ||
for j in range(len(matrix[0])): | ||
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] | ||
#Rotate rows | ||
for i in range(len(matrix)): | ||
l, r = 0, len(matrix[0]) - 1 | ||
while l < r: | ||
matrix[i][l], matrix[i][r] = matrix[i][r], matrix[i][l] | ||
l += 1; r -= 1 | ||
|
||
return matrix | ||
|
||
# Time Complexity = O(N*N) | ||
# Space Complexity = O(1) | ||
|
||
|
||
|
||
# https://www.youtube.com/watch?v=Y72QeX0Efxw | ||
''' | ||
First Transpose(flip matrix over its diagonal) the matrix then rotate every rows | ||
[[1,2,3], [[1,4,7], [[7,4,1], | ||
[4,5,6], =>Transpose=> [2,5,8], =>Rotate rows=> [8,5,2], | ||
[7,8,9]] [3,6,9]] [9,6,3]] | ||
''' | ||
class Solution: | ||
def rotate(self, matrix: List[List[int]]) -> None: | ||
#Transpose | ||
for i in range(len(matrix)): | ||
for j in range(len(matrix[0])): | ||
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] | ||
#Rotate rows | ||
for i in range(len(matrix)): | ||
l, r = 0, len(matrix[0]) - 1 | ||
while l < r: | ||
matrix[i][l], matrix[i][r] = matrix[i][r], matrix[i][l] | ||
l += 1; r -= 1 | ||
|
||
return matrix | ||
|
||
# Time Complexity = O(N*N) | ||
# Space Complexity = O(1) | ||
|
||
|
||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 37 additions & 37 deletions
74
...res whose sum equals to given number n.py → ...res whose sum equals to given number n.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
# https://www.geeksforgeeks.org/minimum-number-of-squares-whose-sum-equals-to-given-number-n/ | ||
# Minimum number of squares whose sum equals to given number n | ||
# A naive recursive Python program to | ||
# find minimum number of squares whose | ||
# sum is equal to a given number | ||
|
||
# Returns count of minimum squares | ||
# that sum to n | ||
def getMinSquares(n): | ||
|
||
# base cases | ||
if n <= 3: | ||
return n | ||
|
||
# getMinSquares rest of the table | ||
# using recursive formula | ||
# Maximum squares required | ||
# is n (1 * 1 + 1 * 1 + ..) | ||
res = n | ||
|
||
# Go through all smaller numbers | ||
# to recursively find minimum | ||
for x in range(1, n + 1): | ||
temp = x * x | ||
if temp > n: | ||
break | ||
else: | ||
res = min(res, 1 + getMinSquares(n - temp)) | ||
|
||
return res | ||
|
||
# Driver code | ||
print(getMinSquares(6)) | ||
|
||
|
||
''' | ||
Output = 3 | ||
# https://www.geeksforgeeks.org/minimum-number-of-squares-whose-sum-equals-to-given-number-n/ | ||
# Minimum number of squares whose sum equals to given number n | ||
# A naive recursive Python program to | ||
# find minimum number of squares whose | ||
# sum is equal to a given number | ||
|
||
# Returns count of minimum squares | ||
# that sum to n | ||
def getMinSquares(n): | ||
|
||
# base cases | ||
if n <= 3: | ||
return n | ||
|
||
# getMinSquares rest of the table | ||
# using recursive formula | ||
# Maximum squares required | ||
# is n (1 * 1 + 1 * 1 + ..) | ||
res = n | ||
|
||
# Go through all smaller numbers | ||
# to recursively find minimum | ||
for x in range(1, n + 1): | ||
temp = x * x | ||
if temp > n: | ||
break | ||
else: | ||
res = min(res, 1 + getMinSquares(n - temp)) | ||
|
||
return res | ||
|
||
# Driver code | ||
print(getMinSquares(6)) | ||
|
||
|
||
''' | ||
Output = 3 | ||
''' |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 15 additions & 15 deletions
30
...riables without using another variable.py → ...riables without using another variable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Swap two variables without using another variable | ||
a = 10 | ||
b = 5 | ||
|
||
a = a + b | ||
b = a - b | ||
a = a - b | ||
|
||
print(f"a = {a}") | ||
print(f"b = {b}") | ||
|
||
|
||
''' | ||
a = 5 | ||
b = 10 | ||
# Swap two variables without using another variable | ||
a = 10 | ||
b = 5 | ||
|
||
a = a + b | ||
b = a - b | ||
a = a - b | ||
|
||
print(f"a = {a}") | ||
print(f"b = {b}") | ||
|
||
|
||
''' | ||
a = 5 | ||
b = 10 | ||
''' |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,93 @@ | ||
import java.io.*; | ||
|
||
// Java program to implement | ||
// a Singly Linked List | ||
public class LinkedList { | ||
|
||
Node head; // head of list | ||
|
||
// Linked list Node. | ||
// This inner class is made static | ||
// so that main() can access it | ||
static class Node { | ||
|
||
int data; | ||
Node next; | ||
|
||
// Constructor | ||
Node(int d) | ||
{ | ||
data = d; | ||
next = null; | ||
} | ||
} | ||
|
||
// Method to insert a new node | ||
public static LinkedList insert(LinkedList list, int data) | ||
{ | ||
// Create a new node with given data | ||
Node new_node = new Node(data); | ||
new_node.next = null; | ||
|
||
// If the Linked List is empty, | ||
// then make the new node as head | ||
if (list.head == null) { | ||
list.head = new_node; | ||
} | ||
else { | ||
// Else traverse till the last node | ||
// and insert the new_node there | ||
Node last = list.head; | ||
while (last.next != null) { | ||
last = last.next; | ||
} | ||
|
||
// Insert the new_node at last node | ||
last.next = new_node; | ||
} | ||
|
||
// Return the list by head | ||
return list; | ||
} | ||
|
||
// Method to print the LinkedList. | ||
public static void printList(LinkedList list) | ||
{ | ||
Node currNode = list.head; | ||
|
||
System.out.print("LinkedList: "); | ||
|
||
// Traverse through the LinkedList | ||
while (currNode != null) { | ||
// Print the data at current node | ||
System.out.print(currNode.data + " "); | ||
|
||
// Go to next node | ||
currNode = currNode.next; | ||
} | ||
} | ||
|
||
// Driver code | ||
public static void main(String[] args) | ||
{ | ||
/* Start with the empty list. */ | ||
LinkedList list = new LinkedList(); | ||
|
||
// | ||
// ******INSERTION****** | ||
// | ||
|
||
// Insert the values | ||
list = insert(list, 1); | ||
list = insert(list, 2); | ||
list = insert(list, 3); | ||
list = insert(list, 4); | ||
list = insert(list, 5); | ||
list = insert(list, 6); | ||
list = insert(list, 7); | ||
list = insert(list, 8); | ||
|
||
// Print the LinkedList | ||
printList(list); | ||
} | ||
} | ||
import java.io.*; | ||
|
||
// Java program to implement | ||
// a Singly Linked List | ||
public class LinkedList { | ||
|
||
Node head; // head of list | ||
|
||
// Linked list Node. | ||
// This inner class is made static | ||
// so that main() can access it | ||
static class Node { | ||
|
||
int data; | ||
Node next; | ||
|
||
// Constructor | ||
Node(int d) | ||
{ | ||
data = d; | ||
next = null; | ||
} | ||
} | ||
|
||
// Method to insert a new node | ||
public static LinkedList insert(LinkedList list, int data) | ||
{ | ||
// Create a new node with given data | ||
Node new_node = new Node(data); | ||
new_node.next = null; | ||
|
||
// If the Linked List is empty, | ||
// then make the new node as head | ||
if (list.head == null) { | ||
list.head = new_node; | ||
} | ||
else { | ||
// Else traverse till the last node | ||
// and insert the new_node there | ||
Node last = list.head; | ||
while (last.next != null) { | ||
last = last.next; | ||
} | ||
|
||
// Insert the new_node at last node | ||
last.next = new_node; | ||
} | ||
|
||
// Return the list by head | ||
return list; | ||
} | ||
|
||
// Method to print the LinkedList. | ||
public static void printList(LinkedList list) | ||
{ | ||
Node currNode = list.head; | ||
|
||
System.out.print("LinkedList: "); | ||
|
||
// Traverse through the LinkedList | ||
while (currNode != null) { | ||
// Print the data at current node | ||
System.out.print(currNode.data + " "); | ||
|
||
// Go to next node | ||
currNode = currNode.next; | ||
} | ||
} | ||
|
||
// Driver code | ||
public static void main(String[] args) | ||
{ | ||
/* Start with the empty list. */ | ||
LinkedList list = new LinkedList(); | ||
|
||
// | ||
// ******INSERTION****** | ||
// | ||
|
||
// Insert the values | ||
list = insert(list, 1); | ||
list = insert(list, 2); | ||
list = insert(list, 3); | ||
list = insert(list, 4); | ||
list = insert(list, 5); | ||
list = insert(list, 6); | ||
list = insert(list, 7); | ||
list = insert(list, 8); | ||
|
||
// Print the LinkedList | ||
printList(list); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## Data Structures and Algorithms in Java | ||
### Please contribute to this folder by sharing solution code in Java. |
This file was deleted.
Oops, something went wrong.