Git Product home page Git Product logo

solutions's Introduction

solutions

Solutions to online programming problems

Please do not use my solutions as your own. I use this repository to organise my answers, to track my progress, and to link to friends to compare solutions; it is not here to help anyone cheat.

I just really enjoy solving these problems.

solutions's People

Contributors

cianlr avatar iandioch 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

solutions's Issues

pivot.py

I have a very similar Pythonic solution to pivot (https://open.kattis.com/problems/pivot) by traversing the lists twice. Adding the candidates when going left to right then removing the candidates right to left (as shown below). The complexity is O(2N) but should round up to O(N). However, my solution failed with "TLE" message.

Is your solution able to successful pass the time limit on Kattis?

_ = int(input())
listy = [int(x) for x in input().split()]

max_left = -2147483647 # smallest 32-bit signed integers
min_right = 2147483647 # largest 32-bit signed integers
pivots = []

for left_iter in listy:
    if left_iter > max_left:
        pivots.append(left_iter)
    if left_iter > max_left:
        max_left = left_iter

        
for right_iter in listy[::-1]:
    if right_iter > min_right and right_iter in pivots:
        pivots.remove(right_iter)
    if right_iter < min_right:
        min_right = right_iter

print(len(pivots))

Wrong test case

On kattis problem : Bank
Test case :
5 4
1200 1
2500 3
2000 2
2500 3
1400 4
your code outputs 8200, where it should output 8400 :
t = 0 , pick 1400
t = 1 , pick 2000
t = 2 , pick 2500
t = 3 , pick 2500

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.