Giter Site home page Giter Site logo

marinskiy / hackerrankpractice Goto Github PK

View Code? Open in Web Editor NEW
1.0K 38.0 411.0 235 KB

170+ solutions to Hackerrank.com practice problems using Python 3, С++ and Oracle SQL

License: MIT License

Python 58.80% TSQL 1.89% C++ 35.75% CMake 3.56%
hackerrank hackerrank-solutions hackerrank-python hackerrank-sql

hackerrankpractice's Issues

New interview questions

Fibonacci

# Iterative solution
def fibonacci(n):
    # special case
    if n == 1:
        return [0]
    # initialize the array
    arr = [0, 1]
    # and populate it, remember to skip the 2 values that are already
present
    for i in range(2, n):
        arr.append(arr[-1]+arr[-2])
    return arr


# Recursive solution
def fibonacci(n):
    # handle special cases
    print(n)
    if n < 2:
        return [0]
    if n < 3:
        return [0, 1]
    # normal case as n decreases from original value to 2
    arr = fibonacci(n-1)
    arr.append(arr[n-2] + arr[n-3])
    return arr

Find the sequence Sum

def getSequenceSum(i, j, k, x):
    cnt_inc = (j - i) // x + 1
    cnt_dec = (j - k) // x + 1
    inc_sum = (cnt_inc * (i + j)) // 2
    dec_sum = (cnt_dec * (j + k)) // 2
    tot_sum = inc_sum + dec_sum - j
    return tot_sum

Maximizing Profit from Stocks

def maximumProfit(prices):
    m = prices.pop()
    maxsum = 0
    arrsum = 0
    for p in reversed(prices):
        m = max(m, p)
        maxsum+=m
        arrsum+=p
    return maxsum-arrsum

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.