subsr97 / daily-coding-problem Goto Github PK
View Code? Open in Web Editor NEWSolutions for Daily Coding Problem.
Solutions for Daily Coding Problem.
class Node:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def createTree(arr):
if not arr:
return None
mid = len(arr)//2
node = Node(arr[mid])
node.left = createTree(arr[:mid])
node.right = createTree(arr[mid+1:])
return node
def findSecondHighest(root):
if root:
global max, smax
current = root.val
if current > max:
max, smax = current, max
elif current < max and current > smax:
smax = current
findSecondHighest(root.left)
findSecondHighest(root.right)
sorted_nums = [1, 2, 3, 4, 15, 6, 17, 8]
tree = createTree(sorted_nums)
smax = tree.val
max = tree.val
findSecondHighest(tree)
print(smax)
This works, but could you advise on how could I do better, or at least how could I avoid those global variables.
The first challenge has a simpler way of writing out a solution, in my opinion, which you may want to consider adding:
from itertools import combinations
def determine_sum(numbers, neededSum):
resulting_values = list(map(sum combinations(numbers, 2)))
if neededSum in resulting_values:
return True
return False
This though I think is technically two passes rather than one, which may make it less ideal for the challenge
lists = [[10, 15, 30], [12, 15, 20, 31], [17, 20, 32]]
one_sorted_list = []
for i in range(len(lists)):
one_sorted_list = sorted([ *one_sorted_list, *lists[i] ])
print(one_sorted_list)
Hi there,
Regarding the problem #1, i am wondering in the second method why not check the remaining value against the primary array and not in knownnumbers.
Is there any specific case which i am missing?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.