GithubHelp home page GithubHelp logo

tannishk / competitive Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 29.0 55 KB

Competitive Programming Question Practise

Python 33.44% Java 29.57% C 10.54% JavaScript 6.86% C++ 14.86% Go 1.52% Ruby 1.36% Scala 1.85%

competitive's Introduction

Competitive Programming Questions

Introduction

This repository is a collection of competitive programming questions that could be asked on interviews. You can always contribute by adding your solution to these questions in the correct folder.

Rules

Feel free to submit answers in a language of your liking.
Only one submission per request will be accepted.
New questions will be posted in issues.
You are also welcome to post new questions in issues
Kindly contribute!

competitive's People

Contributors

aarush22 avatar andrewspeed avatar ankit123rudra avatar aptrishu avatar bing18 avatar bozhko-egor avatar carlovan avatar defcon-007 avatar gillett-hernandez avatar manishsrm avatar patoconnor43 avatar pranayyelugam avatar pratik151 avatar pvdsp avatar ranamahmud avatar sambuddhabasu avatar scavenger1320 avatar sergismj avatar shubham-1996 avatar silentflame avatar sivcan avatar spencerbyw avatar tannishk avatar tonytran avatar troycode avatar userimack avatar vedipen avatar vipin14119 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

competitive's Issues

XOR LinkedList

An XOR linked list is a more memory efficient doubly linked list. Instead of each node holding next and prev fields, it holds a field named both, which is an XOR of the next node and the previous node. Implement an XOR linked list; it has an add(element) which adds the element to the end, and a get(index) which returns the node at index.

If using a language that has no pointers (such as Python), you can assume you have access to get_pointer and dereference_pointer functions that converts between nodes and memory addresses.

Can anyone give the solution of this question in Python with explanation?

Amazon Interview

Print a sequence of numbers starting with N, without using loop, in which A[i+1] = A[i] - 5, if A[i]>0, else A[i+1]=A[i] + 5 repeat it until A[i]=N.

Input:
First line contains number of test cases T. Then following T lines contains an integer N.

Output:
Single line with pattern .

Constraints:
0< N < 10000

Example:
Input:
2
16
10

Output:
16 11 6 1 -4 1 6 11 16
10 5 0 5 10

Explanation:
We basically first reduce 5 one by one until we reach a negative or 0. After we reach 0 or negative, we one by one add 5 until we reach N.

Stack Min Solution in Python

class MinStack(object):

    def __init__(self):
        self.stack = []
        self.min_stack = []
        
    def push(self, x):
        self.stack.append(x)
        if not self.min_stack or x <= self.min_stack[-1]:
            self.min_stack.append(x)
        
    def pop(self):
        n = self.stack.pop()
        if self.min_stack[-1] == n:
            self.min_stack.pop()
        
    def top(self):
        return self.stack[-1]
        
    def getMin(self):
        return self.min_stack[-1]
        

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.