All Questions
Tagged with programming-challenge python-2.x
93
questions
2
votes
1
answer
171
views
LeetCode 839: Similar String Groups III
I'm posting my code for a LeetCode problem. If you'd like to review, please do so. Thank you!
Problem
Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that ...
5
votes
1
answer
89
views
Sorting software version list using Python 2.7 (no modules)
I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution:
...
1
vote
0
answers
156
views
Quora upvotes trends Hackerrank challenge
The following code is my solution to an old problem I found today.
Input Format
Line 1: Two integers, N (1 ≤ N ≤ 106) and window size K (1 ≤ K ≤ N)
Line 2: N positive integers of upvote ...
12
votes
1
answer
6k
views
Google FooBar "Prepare The Bunnies Escape"
I'm currently working through the google FooBar challenge, and I'm on the third level, in which I have to find the distance between the top left and bottom right points on a grid. The grid is filled ...
2
votes
3
answers
2k
views
Given a sorted array nums, remove the duplicates in-place
I wrote an algorithm to solve this challenge but would love some feedback on its efficiency and, if you were an interviewer, what your opinion would be on my solution. I believe my time complexity is \...
10
votes
1
answer
9k
views
Given a string, find the length of the longest substring without repeating characters
I wrote an algorithm that solves this problem but I would love to get some feedback on it (especially since I'm not so confident in my Big \$O\$ skills).
Do you think this is a good quality algorithm?...
3
votes
2
answers
2k
views
Maximum sub-array of non-negative numbers
This is the "Maximum sub-array" problem from CodeChef:
Find out the maximum sub-array of non negative numbers from an
array.
The sub-array should be continuous. That is, a sub-array
...
1
vote
1
answer
965
views
The Substring Game! challenge
This is the Substring Game! challenge from HackerEarth:
Watson gives Sherlock a string (let's denote it by S). Watson calculates all the substrings of S in his favourite order.
According to ...
4
votes
1
answer
1k
views
Genomic Range Query in Python
Recently, I worked on one of the Codility Training - Genomic Range Query (please refer to one of the evaluation report for the detail of the task.
The solution in Python is based on prefix sum, and ...
3
votes
0
answers
362
views
Python2.7 Some xor fun
After doing the Cryptopals challanges, which I found scrolling through codereview, and finally being able to solve set1 challenge 6. I decided to have a little xor fun, and make an automated xor ...
2
votes
2
answers
7k
views
Finding an increasing sequence from a given array in a time-efficient manner in Python
Problem Statement:
Given a sequence of integers as an array, we have to determine whether
it is possible to obtain a strictly increasing sequence by removing no
more than one element from the ...
3
votes
2
answers
719
views
Merging the frequency rankings of boys' names and girls' names
Problem statement:
The html pages for each year which represents the top 1000 most common Girl and Boy names in the order of their frequency are ranked and provided. And they are ranked based on the ...
5
votes
1
answer
300
views
AIO programming challenge - Friendlist - Who has the most friends?
I attempted this sample question from the Australia Infomatics Competition. TL;DR - Each line of input contains two numbers, representing a mutual friendship relationship. The output needs to be the ...
13
votes
2
answers
753
views
A classy DNA nucleobase counter
This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Counting nucleobases in a nucleotide c. The repository with all my up-to-date solutions ...
5
votes
2
answers
785
views
Zigzag Iterator
I've recently solved the LeetCode's "ZigZag iterator" problem:
Given two 1d vectors, implement an iterator to return their elements
alternately.
For example, given two 1d vectors:
...
3
votes
2
answers
2k
views
Hackerrank Submission Optimisation for Melodious Password
Given question from Hackerrank:
a password consists of exactly n lowercase English letters.
the password is melodious, meaning that consonants can only be next to
...
9
votes
2
answers
1k
views
Create two vehicles, move them on a grid based on user input
I have a grid and a class Vehicle, which will have starting point(X, Y on the grid) and direction(one of N,E,S,W) taken from user and there will be commands, ...
6
votes
2
answers
795
views
4 sum challenge (part 2)
This is a continued discussion from (4 sum challenge) by return count only.
Problem
Given four lists A, B, C, D of integer values, compute how many tuples
(i, j, k, l) there are such that A[...
5
votes
0
answers
430
views
4 sum challenge [duplicate]
Problem
Given four lists A, B, C, D of integer values, compute how many tuples
(i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.
To make problem a bit easier, all A, B, C,...
6
votes
2
answers
3k
views
100 Locker Problem Expanded
The locker problem for 100 lockers is simple:
A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, ...
7
votes
2
answers
6k
views
Google FooBar XOR Checksum Challenge
Google FooBar came up a few days ago and I took it as a challenge to learn python quickly while having fun. However, I ran into one challenge today that has left me stumped, I've come up with a ...
6
votes
2
answers
297
views
Find a famous writer in a random string
I'm doing a CodeEval challenge, where the object is to find a famous writers name and a year, inside of a random given string.
You have a set of rows with names of famous writers encoded inside. Each ...
6
votes
2
answers
10k
views
Convert an integer to its Roman numeral equivalent
I got sent a challenge from a friend;
You are given a file that contains numbers, one number per line. Convert the numbers from the file into roman numerals.
...
11
votes
3
answers
6k
views
Rounding a number up to the nearest multiple of a power of 2
I'm doing some programming challenges over at CodeEval and came across a pretty straight forward simple one:
Given numbers x and n, where n is a power of 2, ...
4
votes
2
answers
237
views
Turning numbers into a string of words - challenge
I just completed this challenge at CodeEval.
You are given a positive integer number. This represents the sales made that day in your department store. The payables department however, needs this ...
15
votes
4
answers
8k
views
Google Foobar Challenge: Lucky Triples
Note: Since my time has passed for this challenge, I do not remember exactly the stipulations but will attempt to recapitulate them to the best of my knowledge.
Essentially, the challenge was this:
...
4
votes
2
answers
599
views
Number of possible palindrome sequences
Here is the problem description from hackerearth.com:
Rohan loves Palindromes. Palindrome is a string that read same forward
and backward. For example abba is ...
2
votes
1
answer
93
views
Optimize Performance challenge 'Vinay Queried '
Input:
The first line contains N denoting the length of Target String. This
line is followed by the Target String. The Target String is followed
by an integer Q denoting the number of queries ...
4
votes
2
answers
3k
views
Outputting all possible words which fit a string of letters
I got inspired by this C# question. It asks to write a program to output all possible words (included in a dictionary) which fit a string of letters obtained by swiping the finger over the keyboard, ...
3
votes
1
answer
658
views
Rhezo and divisibility by 7 challenge
There is a big number with N digits and Q questions.
In each question, find if the number formed by the string between
indices Li and Ri is divisible by 7 or not.
Input: First line ...
3
votes
1
answer
547
views
Project Euler #58: Primes along the diagonals of a square spiral
I am working on Project Euler Problem 58:
Starting with 1 and spiralling anticlockwise in the following way, a
square spiral with side length 7 is formed.
...
6
votes
3
answers
13k
views
Cadbury problem solution in Python
Problem Statement
In a School, Chocolate bars have to be distributed to children waiting in a queue. Each Chocolate bar is rectangular in shape. Consider its side lengths are integer values.
The ...
8
votes
2
answers
3k
views
Finding an element in an array that occurs a given number of times
I am trying to solve the below problem from an online coding site:
Fredo is pretty good at dealing large numbers. So, once his friend
Zeus gave him an array of N numbers, followed by Q queries ...
0
votes
2
answers
496
views
Google Foobar Challenge: Spy Snippets in Python [closed]
I am getting all the answers correct. But still the solution is not accepted as only 4/5 tests cases are passed.
I have not posted the whole problem statement but the problem is similar to this.
I ...
8
votes
3
answers
174
views
How to decrease memory usage in codeeval Road Trip challenge
I'm solving easy CodeEval challenges in Python 2.7. Usually my solutions use around 256 bytes of memory according to CodeEval. With Road Trip however while time used is still low (30-40ms), memory is >...
3
votes
2
answers
899
views
SPOJ ADDREV challenge - Adding reversed numbers
I'm a beginner Python (2.7) programmer, and I've just started solving basic problems on SPOJ. I correctly solved the ADDREV problem (http://www.spoj.com/problems/ADDREV/), however my code takes 0.06s ...
0
votes
2
answers
3k
views
Calculating and printing a credit card balance
I am working on a problem that simply calculates and prints the credit card balance. I hope this code can be improved/optimized a lot.
I am from a Java background. If it was Java code, I would have ...
8
votes
2
answers
707
views
Sum of prime factors of binomial coefficients over 9000!\${}\$
The problem
I have lately been working Project Euler: 231:
The prime factorisation of binomial coefficients
The binomial coefficient \$ ^{10}C_3 = 120 \$.
\$ 120 = 2^3 × 3 × 5 = 2 × 2 ×...
3
votes
1
answer
1k
views
Minimum window substring
The minimum window substring problem from leetcode.com asks:
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity \$O(n)\$.
...
4
votes
3
answers
2k
views
Codewars "Find the Parity Outlier" code
I completed this Codewars exercise. Here are the instructions:
You are given an array (which will have a length of at least 3, but
could be very large) containing integers. The integers in the ...
2
votes
2
answers
194
views
Circular primes below 10^1025
The problem
Project Euler: 35 is stated in the following way
Circular primes
Problem 35
The number, 197, is called a circular prime because all rotations of
the digits: 197, 971, and ...
3
votes
1
answer
111
views
Beating a dead horse: Project Euler 4
The task
A palindromic number reads the same both ways. The largest palindrome
made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the ...
2
votes
2
answers
2k
views
Counting pairs of integers which have a predefined difference
I'm doing this HackerRank problem:
Given \$N\$ integers, count the number of pairs of integers whose difference is \$K\$.
So far, I've ended up with this code:
...
4
votes
1
answer
2k
views
Checking to see if array can be sorted using only one operation
I'm doing this HackerRank problem, which asks whether an array of up to 100000 integers can be sorted in ascending order by exactly one of the following:
swapping two elements
reversing a subarray
...
6
votes
1
answer
845
views
Palindromes that are sum of consecutive squares
I have been working on a Project Euler: 125, which took me ages to solve. The problem and source are cited below
The palindromic number 595 is interesting because it can be written as
the sum of ...
4
votes
3
answers
2k
views
User ranking system
I have written my first code of object oriented Python. Prior to this I have spent a week on learning the concepts and understanding the technique. I would appreciate it somebody reviews this and give ...
8
votes
2
answers
3k
views
Printing letters in order like a pyramid
There is this hackerrank question, where we need a rhombus of letters. As to my opinion it can be viewed as some fractal, or similar logic.
Well I solved the question, but I am obviously disappointed ...
5
votes
3
answers
520
views
"Researcher Hatim is right or wrong" challenge
I wrote a program to solve a problem, I am not so good in python so want help to find areas where this program can be improved or simplified and readable too:-
I got this problem in a code challenge
...
1
vote
2
answers
783
views
Project Euler 21: Sum of Amicable Numbers
Problem 21:
Let \$d(n)\$ be defined as the sum of proper divisors of \$n\$ (numbers less than \$n\$ which divide evenly into \$n\$).
If \$d(a) = b\$ and \$d(b) = a\$, where \$a ≠ b\$, then \$a\$ ...
5
votes
1
answer
254
views
Project Euler 92: sum of squares of digits until a loop is encountered
This is my solution to Project Euler #92:
A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.
For example,
...