Skip to content
Merged
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions solutions/python/practice105.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Minimum Operations to Reduce Number to One
# Source: https://www.geeksforgeeks.org/dsa/reduce-a-number-to-1-by-performing-given-operations/
# Note: Greedy loop: halve even numbers; for odd numbers subtract 1, unless (n - 1) / 2 is odd and not 1, where adding 1 reaches a shorter chain of halvings

n = int(input('Enter a positive integer: '))
op = 0
Expand Down
1 change: 1 addition & 0 deletions solutions/python/practice106.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Backspace String Compare
# Source: https://leetcode.com/problems/backspace-string-compare/
# Note: Builds the final text of s with a list as a stack ('#' pops the last character), then compares the result against t as entered

s = input('Enter string s: ')
t = input('Enter string t: ')
Expand Down
1 change: 1 addition & 0 deletions solutions/python/practice107.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Buddy Strings Challenge
# Source: https://leetcode.com/problems/buddy-strings/
# Note: Brute force: tries swapping every pair of positions in a and checks whether the swapped string equals b

a = input('Enter string A: ')
b = input('Enter string B: ')
Expand Down
1 change: 1 addition & 0 deletions solutions/python/practice108.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Largest Number At Least Twice of Others
# Source: https://leetcode.com/problems/largest-number-at-least-twice-of-others/
# Note: Finds the maximum, then checks that every other element is at most half of it; prints the maximum's index if all pass, otherwise -1

n = int(input('Enter the number of integers: '))
print('Enter the integers:')
Expand Down
1 change: 1 addition & 0 deletions solutions/python/practice109.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Find the Missing Number
# Source: https://leetcode.com/problems/missing-number/
# Note: Sorts the array, then scans neighbouring elements for the first gap; the missing number is one more than the element before the gap

n = int(input('Enter the number of elements: '))
print(f'Enter {n} elements (between 1 and {n + 1}): ')
Expand Down
1 change: 1 addition & 0 deletions solutions/python/practice110.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Intersection of Two Arrays
# Source: https://leetcode.com/problems/intersection-of-two-arrays/
# Note: Converts both arrays to sets and prints their intersection, so each common element appears once

n = int(input('Enter the size of the first array: '))
print(f"Enter {n} elements of the first array (sorted):")
Expand Down
1 change: 1 addition & 0 deletions solutions/python/practice111.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Product of Array Except Self
# Source: https://leetcode.com/problems/product-of-array-except-self/
# Note: Brute force: for each index, multiplies every other element into the answer (no division), O(n^2)

n = int(input('Enter the number of elements: '))
print(f"Enter {n} elements:")
Expand Down
1 change: 1 addition & 0 deletions solutions/python/practice112.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Problem: Count CamelCase Words
# Source: https://www.hackerrank.com/challenges/camelcase/problem
# Note: Walks the string once, starting a new word at each uppercase letter, and prints how many words were found

s = input('Enter the CamelCase string: ')

Expand Down
Loading