Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions Algorithms/Dynamic Programming/rod_cutting_problem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <limits.h>
#include <stdio.h>

int max(int a, int b) { return (a > b) ? a : b; }

int cutRod(int price[], int n)
{
if (n <= 0)
return 0;
int max_val = INT_MIN;
for (int i = 0; i < n; i++)
max_val = max(max_val, price[i] + cutRod(price, n - i - 1));

return max_val;
}

int main()
{
int arr[] = { 1, 5, 8, 9, 10, 17, 17, 20 };
int size = sizeof(arr) / sizeof(arr[0]);
printf("Maximum Obtainable Value is %d", cutRod(arr, size));
getchar();
return 0;
}
24 changes: 24 additions & 0 deletions Data Structures/Heap/Python/maxheap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import heapq

class Solution:

def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]:

maxHeap = []

for (x, y) in points:
distance = math.sqrt(x*x + y*y)

if len(maxHeap) >= K:
if -1 * distance > maxHeap[0][0]:
heapq.heappushpop(maxHeap, [-1 * distance, [x, y]])
else:
heapq.heappush(maxHeap, [-1 * distance, [x, y]])

resList = []

for _ in range(K):
resList.append(heapq.heappop(maxHeap)[1])

# return the list
return resList
3 changes: 3 additions & 0 deletions Data Structures/Palindrome/py_palindrome_oneliner
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
s=input()
is_palindrome = lambda phrase: phrase == phrase[::-1]
print(is_palindrome(s))