As of May 31, 2023, we have updated our Code of Conduct.

All Questions

Filter by
Sorted by
Tagged with
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 ...
Emma's user avatar
  • 3,477
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: ...
user40929's user avatar
  • 163
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 ...
akshaynagpal's user avatar
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 ...
Isaac-Neil Zanoria's user avatar
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 \...
DCS's user avatar
  • 375
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?...
DCS's user avatar
  • 375
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 ...
Latika Agarwal's user avatar
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 ...
katty's user avatar
  • 585
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 ...
sivan shani's user avatar
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 ...
Ludisposed's user avatar
  • 11.5k
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 ...
Sreedhar Danturthi's user avatar
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 ...
Sreedhar Danturthi's user avatar
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 ...
John Hon's user avatar
  • 171
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 ...
Mast's user avatar
  • 13k
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: ...
alecxe's user avatar
  • 17.2k
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 ...
Sreetam Das's user avatar
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, ...
Brandon Bishop's user avatar
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[...
Lin Ma's user avatar
  • 3,443
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,...
Lin Ma's user avatar
  • 3,443
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, ...
Anthony Pham's user avatar
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 ...
RoflcopterV RoflcopterV's user avatar
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 ...
papasmurf's user avatar
  • 421
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. ...
papasmurf's user avatar
  • 421
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, ...
papasmurf's user avatar
  • 421
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 ...
Pyth0nicPenguin's user avatar
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: ...
Edwin Rice's user avatar
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 ...
Shashank's user avatar
  • 255
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 ...
sandesh indavara's user avatar
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, ...
Graipher's user avatar
  • 40.7k
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 ...
sandesh indavara's user avatar
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. ...
Arvind Ganesh's user avatar
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 ...
divya's user avatar
  • 61
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 ...
krishna's user avatar
  • 183
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 ...
Animesh Pandey's user avatar
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 >...
Alaris's user avatar
  • 83
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 ...
Abhimanyu Sahai's user avatar
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 ...
srk's user avatar
  • 608
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 ×...
N3buchadnezzar's user avatar
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)\$. ...
Lin Ma's user avatar
  • 3,443
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 ...
zthomas.nc's user avatar
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 ...
N3buchadnezzar's user avatar
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 ...
N3buchadnezzar's user avatar
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: ...
Sidharth Samant's user avatar
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 ...
Sidharth Samant's user avatar
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 ...
N3buchadnezzar's user avatar
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 ...
Susmita Ghosh's user avatar
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 ...
Rockybilly's user avatar
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 ...
SeasonedNoob's user avatar
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\$ ...
Barry's user avatar
  • 18.4k
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, ...
Barry's user avatar
  • 18.4k