Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
455be01
Dynamic Programming: Coint-Change-Problem
Abhishek2019 Feb 6, 2018
5f65311
README.md file modified
Abhishek2019 Feb 6, 2018
4bb49cf
Angry Professor Solution Added
satyam857 Oct 22, 2018
2edd5aa
The Hurdle Race Solution is Added
satyam857 Oct 22, 2018
26f50d5
The Maximum Subarray Solution is Added
satyam857 Oct 22, 2018
b4e114f
Linked List Print the Element problem solved
satyam857 Oct 22, 2018
c244f81
Solution of Tree Preorder traversal
satyam857 Oct 22, 2018
ecb8d88
Merge pull request #1 from satyam857/master
Abhishek2019 Oct 22, 2018
a985d1b
Merge pull request #2 from satyam857/master
Abhishek2019 Oct 22, 2018
39907ab
Merge pull request #3 from satyam857/master
Abhishek2019 Oct 22, 2018
70e3236
Merge pull request #4 from satyam857/master
Abhishek2019 Oct 23, 2018
a9e472a
Tree Inorder Traversal Solution is Added
invalid-email-address Oct 23, 2018
c5388e1
Merge pull request #5 from satyam857/master
Abhishek2019 Oct 23, 2018
312a15a
Added Sherlock and squares in inplementation
V7kas Oct 30, 2018
2367a79
Merge pull request #6 from V7kas/master
Abhishek2019 Oct 30, 2018
221dde7
Adder Designer Pdf Viewer in implementation
V7kas Oct 30, 2018
bab7f5c
Merge pull request #7 from V7kas/master
Abhishek2019 Oct 30, 2018
754a083
Added Cats and mouse in implementation
V7kas Oct 30, 2018
0edf9d8
Merge pull request #8 from V7kas/master
Abhishek2019 Oct 30, 2018
cec7fbf
Added Utopian tree in implementation
V7kas Oct 30, 2018
c4fdff7
Merge pull request #9 from V7kas/master
Abhishek2019 Oct 30, 2018
aa84612
Added Append and delete in implementation and updated the readme file
V7kas Oct 30, 2018
9aac95d
Merge pull request #10 from V7kas/master
Abhishek2019 Oct 30, 2018
6e82644
MCQ1 Answer is added
invalid-email-address Oct 28, 2019
7121b66
MCQ solution location updated in Readme.md file
invalid-email-address Oct 28, 2019
a46b9e9
Data Structure MCQ 2 Solution is added
invalid-email-address Oct 28, 2019
76212e4
Readmi.md fix
invalid-email-address Oct 28, 2019
3d02d9b
MCQ3 Solution is added
invalid-email-address Oct 28, 2019
11672c3
Merge pull request #11 from satyam857/master
Abhishek2019 Oct 29, 2019
af5d642
README.md Updated
invalid-email-address Oct 30, 2019
ed5578c
Merge pull request #12 from satyam857/master
Abhishek2019 Oct 30, 2019
9027ce3
Merge pull request #13 from satyam857/master
Abhishek2019 Oct 30, 2019
b6c0c19
Finla README.md Update
invalid-email-address Oct 30, 2019
d8a297e
Merge pull request #14 from satyam857/master
Abhishek2019 Oct 30, 2019
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
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ The index below is auto-generated. See [update-challenge-list.py](util/update-ch
Index
======

* [Algorithms](#algorithms) (60/409)
* [Data Structures](#data-structures) (11/114)
* [Algorithms](#algorithms) (61/409)
* [Data Structures](#data-structures) (17/114)
* [Mathematics](#mathematics) (1/250)

Algorithms
------

* [Warmup](#warmup) (9/9)
* [Implementation](#implementation) (8/59)
* [Implementation](#implementation) (10/59)
* [Strings](#strings) (11/45)
* [Sorting](#sorting) (5/18)
* [Search](#search) (3/23)
* [Graph Theory](#graph-theory) (2/58)
* [Greedy](#greedy) (8/22)
* [Dynamic Programming](#dynamic-programming) (8/94)
* [Dynamic Programming](#dynamic-programming) (10/94)
* [Constructive Algorithms](#constructive-algorithms) (2/11)
* [Bit Manipulation](#bit-manipulation) (0/25)
* [Recursion](#recursion) (3/10)
Expand Down Expand Up @@ -55,13 +55,13 @@ Algorithms
8 | [Bon App��tit](https://www.hackerrank.com/challenges/bon-appetit) | [Solution & Comment](solution/practice/algorithms/implementation/bon-appetit/solution.py)
9 | [Sock Merchant](https://www.hackerrank.com/challenges/sock-merchant) | [Solution & Comment](solution/practice/algorithms/implementation/sock-merchant/solution.py)
10 | [Drawing Book ](https://www.hackerrank.com/challenges/drawing-book) | WIP
11 | [Cats and a Mouse](https://www.hackerrank.com/challenges/cats-and-a-mouse) | WIP
11 | [Cats and a Mouse](https://www.hackerrank.com/challenges/cats-and-a-mouse) | [Solution & Comment](solution/practice/algorithms/implementation/Cats-and-a-mouse/solution.py)
12 | [Picking Numbers](https://www.hackerrank.com/challenges/picking-numbers) | WIP
13 | [Climbing the Leaderboard](https://www.hackerrank.com/challenges/climbing-the-leaderboard) | WIP
14 | [The Hurdle Race](https://www.hackerrank.com/challenges/the-hurdle-race) | WIP
15 | [Designer PDF Viewer](https://www.hackerrank.com/challenges/designer-pdf-viewer) | WIP
16 | [Utopian Tree](https://www.hackerrank.com/challenges/utopian-tree) | WIP
17 | [Angry Professor](https://www.hackerrank.com/challenges/angry-professor) | WIP
14 | [The Hurdle Race](https://www.hackerrank.com/challenges/the-hurdle-race) | [Solution & Comment](solution/practice/algorithms/implementation/TheHurdleRace/solution.py)
15 | [Designer PDF Viewer](https://www.hackerrank.com/challenges/designer-pdf-viewer) | [Solution & Comment](solution/practice/algorithms/implementation/Designer-PDF-Viewer/solution.py)
16 | [Utopian Tree](https://www.hackerrank.com/challenges/utopian-tree) | [Solution & Comment](solution/practice/algorithms/implementation/Utopian-Tree/solution.py)
17 | [Angry Professor](https://www.hackerrank.com/challenges/angry-professor) | [Solution & Comment](solution/practice/algorithms/implementation/AngryProfessor/solution.py)
18 | [Beautiful Days at the Movies](https://www.hackerrank.com/challenges/beautiful-days-at-the-movies) | WIP
19 | [Viral Advertising](https://www.hackerrank.com/challenges/strange-advertising) | WIP
20 | [Save the Prisoner!](https://www.hackerrank.com/challenges/save-the-prisoner) | WIP
Expand All @@ -70,8 +70,8 @@ Algorithms
23 | [Jumping on the Clouds: Revisited](https://www.hackerrank.com/challenges/jumping-on-the-clouds-revisited) | WIP
24 | [Find Digits](https://www.hackerrank.com/challenges/find-digits) | WIP
25 | [Extra Long Factorials](https://www.hackerrank.com/challenges/extra-long-factorials) | WIP
26 | [Append and Delete](https://www.hackerrank.com/challenges/append-and-delete) | WIP
27 | [Sherlock and Squares](https://www.hackerrank.com/challenges/sherlock-and-squares) | WIP
26 | [Append and Delete](https://www.hackerrank.com/challenges/append-and-delete) | [Solution & Comment](solution/practice/algorithms/implementation/Append-and-Delete/solution.py)
27 | [Sherlock and Squares](https://www.hackerrank.com/challenges/sherlock-and-squares) | [Solution & Comment](solution/practice/algorithms/implementation/Sherlock-And-Squares/solution.py)
28 | [Library Fine](https://www.hackerrank.com/challenges/library-fine) | WIP
29 | [Cut the sticks](https://www.hackerrank.com/challenges/cut-the-sticks) | WIP
30 | [Non-Divisible Subset](https://www.hackerrank.com/challenges/non-divisible-subset) | WIP
Expand Down Expand Up @@ -294,7 +294,7 @@ Algorithms
### Dynamic Programming
\# | Challenge | Solution
:---:|:---:|:---:
1 | [The Coin Change Problem](https://www.hackerrank.com/challenges/coin-change) | WIP
1 | [The Coin Change Problem](https://www.hackerrank.com/challenges/coin-change) | [Solution & Comment](solution/practice/algorithms/dynamic-programming/Coin-Change-Problem/solution.py)
2 | [Equal](https://www.hackerrank.com/challenges/equal) | WIP
3 | [Sherlock and Cost](https://www.hackerrank.com/challenges/sherlock-and-cost) | [Solution & Comment](solution/practice/algorithms/dynamic-programming/sherlock-and-cost/solution.py)
4 | [Kingdom Division](https://www.hackerrank.com/challenges/kingdom-division) | WIP
Expand All @@ -305,7 +305,7 @@ Algorithms
9 | [Abbreviation](https://www.hackerrank.com/challenges/abbr) | [Solution & Comment](solution/practice/algorithms/dynamic-programming/abbr/solution.py)
10 | [Decibinary Numbers](https://www.hackerrank.com/challenges/decibinary-numbers) | WIP
11 | [Fair Cut](https://www.hackerrank.com/challenges/fair-cut) | WIP
12 | [The Maximum Subarray](https://www.hackerrank.com/challenges/maxsubarray) | WIP
12 | [The Maximum Subarray](https://www.hackerrank.com/challenges/maxsubarray) | [Solution & Comment](solution/practice/algorithms/dynamic-programming/TheMaximumSubarray/solution.py)
13 | [Angry Children 2](https://www.hackerrank.com/challenges/angry-children-2) | WIP
14 | [Sherlock's Array Merging Algorithm](https://www.hackerrank.com/challenges/sherlocks-array-merging-algorithm) | WIP
15 | [Prime Digit Sums](https://www.hackerrank.com/challenges/prime-digit-sums) | WIP
Expand Down Expand Up @@ -494,14 +494,14 @@ Data Structures
------

* [Arrays](#arrays) (6/6)
* [Linked Lists](#linked-lists) (0/15)
* [Trees](#trees) (0/15)
* [Linked Lists](#linked-lists) (1/15)
* [Trees](#trees) (2/15)
* [Balanced Trees](#balanced-trees) (0/3)
* [Stacks](#stacks) (0/9)
* [Queues](#queues) (0/5)
* [Heap](#heap) (0/4)
* [Disjoint Set](#disjoint-set) (4/4)
* [Multiple Choice](#multiple-choice) (0/3)
* [Multiple Choice](#multiple-choice) (3/3)
* [Trie](#trie) (0/2)
* [Advanced](#advanced) (1/48)

Expand All @@ -518,7 +518,7 @@ Data Structures
### Linked Lists
\# | Challenge | Solution
:---:|:---:|:---:
1 | [Print the Elements of a Linked List](https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list) | WIP
1 | [Print the Elements of a Linked List](https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list) | [Solution & Comment](solution/practice/data-structures/linked-list/print-the-elements-of-a-linked-list/solution.py)
2 | [Insert a Node at the Tail of a Linked List](https://www.hackerrank.com/challenges/insert-a-node-at-the-tail-of-a-linked-list) | WIP
3 | [Insert a node at the head of a linked list](https://www.hackerrank.com/challenges/insert-a-node-at-the-head-of-a-linked-list) | WIP
4 | [Insert a node at a specific position in a linked list](https://www.hackerrank.com/challenges/insert-a-node-at-a-specific-position-in-a-linked-list) | WIP
Expand All @@ -537,9 +537,9 @@ Data Structures
### Trees
\# | Challenge | Solution
:---:|:---:|:---:
1 | [Tree: Preorder Traversal](https://www.hackerrank.com/challenges/tree-preorder-traversal) | WIP
1 | [Tree: Preorder Traversal](https://www.hackerrank.com/challenges/tree-preorder-traversal) | [Solution & Comment](solution/practice/data-structures/trees/TreePreorderTraversal/solution.py)
2 | [Tree: Postorder Traversal](https://www.hackerrank.com/challenges/tree-postorder-traversal) | WIP
3 | [Tree: Inorder Traversal](https://www.hackerrank.com/challenges/tree-inorder-traversal) | WIP
3 | [Tree: Inorder Traversal](https://www.hackerrank.com/challenges/tree-inorder-traversal) | [Solution & Comment](solution/practice/data-structures/trees/TreeInorderTraversal/solution.py)
4 | [Tree: Height of a Binary Tree](https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree) | WIP
5 | [Tree : Top View](https://www.hackerrank.com/challenges/tree-top-view) | WIP
6 | [Tree: Level Order Traversal](https://www.hackerrank.com/challenges/tree-level-order-traversal) | WIP
Expand Down Expand Up @@ -601,9 +601,9 @@ Data Structures
### Multiple Choice
\# | Challenge | Solution
:---:|:---:|:---:
1 | [ Data Structures MCQ 1](https://www.hackerrank.com/challenges/how-well-do-you-know-trees) | WIP
2 | [ Data Structures MCQ 2](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures) | WIP
3 | [ Data Structures MCQ 3](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures-1) | WIP
1 | [ Data Structures MCQ 1](https://www.hackerrank.com/challenges/how-well-do-you-know-trees) | [Solution & Comment](solution/practice/data-structures/multiple-choice/how-well-do-you-know-trees/solution.py)
2 | [ Data Structures MCQ 2](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures) | [Solution & Comment](solution/practice/data-structures/multiple-choice/are-you-an-expert-on-data-structures/solution.py)
3 | [ Data Structures MCQ 3](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures-1) | [Solution & Comment](solution/practice/data-structures/multiple-choice/are-you-an-expert-on-data-structures-1/solution.py)

### Trie
\# | Challenge | Solution
Expand Down
2 changes: 1 addition & 1 deletion challenges.json
Original file line number Diff line number Diff line change
Expand Up @@ -3297,4 +3297,4 @@
"name": "mathematics"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/python3

import sys

def getWays(n, c):
workArea = [0 for i in range(n+1)]
workArea[0] = 1
countCoin = 0


while(countCoin < len(c)):

for i in range(1,n+1):

if(c[countCoin]<=i):
workArea[i] = workArea[i]+workArea[i-c[countCoin]]
countCoin += 1

return(workArea[-1])



n, m = input().strip().split(' ')
n, m = [int(n), int(m)]
c = list(map(int, input().strip().split(' ')))
# Print the number of ways of making change for 'n' units using coins having the values given by 'c'
ways = getWays(n, c)
print(ways)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the maxSubarray function below.
def maxSubarray(arr):
sub_array_sum = -sys.maxsize
sub_sequ_sum = arr[0]
current_sum=0

for i in arr:
current_sum += i
if sub_array_sum < current_sum:
sub_array_sum = current_sum
if current_sum < 0:
current_sum=0
for i in range(1, len(arr)):
if arr[i] > 0 and sub_sequ_sum >= 0 :
sub_sequ_sum += arr[i]
elif sub_sequ_sum < 0 and sub_sequ_sum < arr[i]:
sub_sequ_sum = arr[i]
return [sub_array_sum,sub_sequ_sum]




if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

t = int(input())

for t_itr in range(t):
n = int(input())

arr = list(map(int, input().rstrip().split()))

result = maxSubarray(arr)

fptr.write(' '.join(map(str, result)))
fptr.write('\n')

fptr.close()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
testcase = int(input())
for i in range(testcase):
n , k = list(map(int,input().split(" ")))
count = 0
s = list(map(int,input().split(" ")))
for j in s:
if(j <= 0):
count +=1
if(count >= k):
print("NO")
else:
print("YES")

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def appendAndDelete(s, t, k):
numSameChars = min(len(s), len(t))
for i in range(len(t)):
if s[:i] != t[:i]:
numSameChars = i - 1
break

diff = len(s) - numSameChars + len(t) - numSameChars
return 'Yes' if (diff <= k and diff % 2 == k % 2) or len(s) + len(t) < k else 'No'


if __name__ == '__main__':
s = input()
t = input()
k = int(input())
result = appendAndDelete(s, t, k)
print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def catAndMouse(ca, cb, m):
if abs(m - ca) == abs(m - cb):
return "Mouse C"
else:
return "Cat A" if abs(m - ca) < abs(m - cb) else "Cat B"

if __name__ == '__main__':
q = int(input())
for q_itr in range(q):
xyz = input().split()
x = int(xyz[0])
y = int(xyz[1])
z = int(xyz[2])
result = catAndMouse(x, y, z)

print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def designerPdfViewer(h, word):
word_height = [h[ord(c)-ord("a")] for c in word ]
return max(word_height)*len(word)


if __name__ == '__main__':
h = list(map(int, input().rstrip().split()))
word = input()
result = designerPdfViewer(h, word)
print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import math


def squares(a, b):
return math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1


if __name__ == '__main__':
q = int(input())
for q_itr in range(q):
ab = input().split()
a = int(ab[0])
b = int(ab[1])
result = squares(a, b)
print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/python3

import sys

def hurdleRace(k, height):
temp = max(height)-k
if (temp > 0):
return temp
else:
return 0

if __name__ == "__main__":
n, k = input().strip().split(' ')
n, k = [int(n), int(k)]
height = list(map(int, input().strip().split(' ')))
result = hurdleRace(k, height)
print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def utopianTree(n):
height = 1
for i in range(n):
if i % 2 == 0:
height *= 2
else:
height += 1
return height


if __name__ == '__main__':
t = int(input())
for t_itr in range(t):
n = int(input())
result = utopianTree(n)
print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# For student i, we can find two (possibly empty) ranges
# of time when they are available:
# * [0, i - t_i]
# * the first one wrapped around 0, which is (i, i - t_i + n]
#
# To get the available student number, we then have to add
# one to the counting array for each minute mark in these intervals.
# This can be done in O(n) time using the awesome algorithm
# described at http://stackoverflow.com/a/18410273.

n = int(input())
A = [0] * (n + 1)
for i, x in enumerate(map(int, input().split())):
r1 = max(-1, i - x) + 1
r2 = min(max(i, i - x + n) + 1, n)
A[0] += 1
A[r1] -= 1
A[i + 1] += 1
A[r2] -= 1
for i in range(n):
A[i + 1] += A[i]
print(A.index(max(A)) + 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Complete the printLinkedList function below.

#
# For your reference:
#
# SinglyLinkedListNode:
# int data
# SinglyLinkedListNode next
#
#
def printLinkedList(head):
if head == None:
return;
n = head
while(n != None):
print(n.data)
n = n.next
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Stack")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Segment Tree")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("n-1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Node is defined as
self.left (the left child of the node)
self.right (the right child of the node)
self.info (the value of the node)
"""
def inOrder(root):
if root != None :
inOrder(root.left)
print(root.info,end=" ")
inOrder(root.right)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Node is defined as
self.left (the left child of the node)
self.right (the right child of the node)
self.info (the value of the node)
"""
def preOrder(root):
if root != None :
print(root.info,end=" ")
preOrder(root.left)
preOrder(root.right)
return