Code Monkey home page Code Monkey logo

daily-coding-problem's People

Contributors

subsr97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

daily-coding-problem's Issues

QNo 36 Query

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.

Confusion in #1

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?

merge sorted lists in less lines of code

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)

Consider alternative solution for sum-in-pairs (first challenge)

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.