Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [programming-challenge]

Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.

1
vote
0answers
5 views

Hamming Distance in Python

I was solving this Leetcode challenge about Hamming Distance. Would love feedback on my syntax and code style. Here's the challenge description: The Hamming distance between two integers is the ...
1
vote
0answers
17 views

Codewars: N smallest elements in original order

I am consistently timing out on the mentioned kata: Task You will be given an array of random integers and a number n. You have to extract n smallest integers out of it preserving the original ...
1
vote
2answers
22 views

SPOJ Adding reversed number in Java

I just started to practice for competitive programming and just started to solve the most solved problems on SPOJ. This is what I made for ADDREV: Adding reversed numbers in Java (https://www.spoj....
5
votes
1answer
57 views

Linear regression on points specified by the user in a GUI

Here's my take on the Linear Regression exercise from John Zelle's Python book. Open a window, let the user click on as many points as they want. Upon pressing the "Done" button the regression line ...
3
votes
1answer
39 views

Leetcode 102: Binary tree level-order traversal in Swift

102. Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary ...
3
votes
3answers
80 views

LeetCode Problem 66 : Plus One

I have started practicing problems in leetcode and I solved the following problem on LeetCode. The challenge is : Given a non-empty array of digits representing a non-negative integer, plus one to ...
-2
votes
0answers
22 views

Generalized Hailstone that converges with the sequences [on hold]

Can someone please help me solve this problem in python? Thank you in advance! ...
1
vote
1answer
35 views

Leetcode 3Sum problem using hashmap in Python

For practice, I solved Leetcode 15. 3Sum question: Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives ...
3
votes
2answers
74 views

Find the longest sub string of a word after concatenation of given words array

An Array of N words is given. Each word consists of small letters ('a'-'z'). Our goal is to concatenate the words in such a way as to obtain a single word with longest possible substring composed of ...
4
votes
3answers
271 views

Collect subsequences of consecutive integers

I've written a function to split a list into several lists with consecutive integers, e.g.: extract_subsequences([1,2,3,7,8,9]) ...
3
votes
1answer
77 views

Word break problem with recursion and memorization [closed]

For practice, I solved Leetcode 139. worbreak question: Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-...
5
votes
1answer
233 views

Count pairs in list of integers such that their addition is equal to the input value

Given a List<int>, the problem I am trying to solve is: Find the number of unique pairs in List<int> such that their ...
2
votes
2answers
162 views

Mr. Muffin's ball-passing game

I have an assignment to solve this problem. There are a total of 18 test case files, 5 of which I have failed due to exceeding some time limit on the script and I am unable to verify if there are any ...
0
votes
2answers
74 views

Leetcode: Merging 2 sorted lists

https://leetcode.com/problems/merge-two-sorted-lists/ Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. ...
9
votes
4answers
1k views

Compute binary XOR of all integers in a range, mod 2

here I am taking 3 inputs. 1st input will take test cases and the other two input will take starting and ending range. the program is running fine as expected but the limit of this question for ...
21
votes
3answers
4k views

Leetcode: Valid parentheses

https://leetcode.com/problems/valid-parentheses/ Given a string containing just the characters (, ), ...
2
votes
1answer
70 views

Leetcode Three Sum in Python

Here's my solution for the Leet Code's Three Sum problem -- would love feedback on (1) code efficiency and (2) style/formatting. This is Python 3. Problem: Given an array nums of n integers, are ...
1
vote
2answers
124 views

Faster code for leetcode reverse int

This is my solution for the leetcode reverse int question: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 ...
0
votes
0answers
59 views

Time limit exceeded on HackerRank “Username Disparity”

Here is the hackerrank question: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of ...
2
votes
2answers
101 views

Project Euler problem 86 taking a long time

I'm trying to solve problem 86 in Project Euler. After some tinkering, I managed to unroll the DP solution into a loop. But still the solution takes >150s to complete. What can I do to improve the ...
2
votes
5answers
159 views

Largest binary gap

I took a task from Codility to find longest sequence of zeros in binary representation of an integer. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. ...
3
votes
1answer
59 views

Python Inheritance and Class (Hackerank problem)

I just deep dived to Python and I came with this Hackerrank problem: Create two class, Person with firstName, ...
3
votes
5answers
464 views

Finding Isogram Word

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times. The ...
8
votes
4answers
2k views

Reversing a string - two approaches

Test Case: Input- "I'm hungry!" Output- "!yrgnuh m'I" Approach 1: In this approach, I used a empty string and bind it with the input string reversely. ...
3
votes
0answers
52 views

Kattis Ants challenge

I am trying to learn Haskell doing some contest problems. I have worked a bit with the language but still have a very long way ahead. Right now I am working with a problem called Ants: An army of ...
3
votes
0answers
68 views

Given an input string and a pattern, implement wildcard pattern matching

I have been trying to solve "Wildcard Matching" on leetcode. I know there are more "manual" ways to solve this without using the RE library. But I would like to know if passing the time limit is ...
1
vote
1answer
37 views

DM::OJ Slot Machines challenge in Python 3

I have written a solution to the Slot Machines challenge on DM::OJ: Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to ...
2
votes
2answers
74 views

The next prime number in Python

I have written a solution to a DM::OJ exercise to find the next Prime Number after a given number (input). I'm seeking to optimize it so that it will run for any number up to ...
1
vote
3answers
77 views

Kattis prime reduction challenge

I am solving the Prime Reduction challenge on Kattis. Consider the following process, which we’ll call prime reduction. Given an input x: if x is prime, print x and stop factor x into its ...
3
votes
3answers
120 views

Find MD5-hash whose hexadecimals starts like digits of π

I saw a programming puzzle. Find a string containing letters from a to z such that its MD5-hash starts like 314159265359. I am a junior programmer so I would like to know if I can solve the problem ...
0
votes
2answers
48 views

Euler Project #3 Largest prime factor timeout

I have been recently trying my hands on Euler's Project through HackerRank and got stuck with project #3 where you have to find the Largest Prime Factor. Question: The prime factors of 13195 are 5, 7,...
3
votes
1answer
53 views

Leetcode Mountain Array

I've been working on longest mountain in array on Leetcode: Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: ...
4
votes
4answers
127 views

Python solution to The Hardest Logic Puzzle Ever

The The Hardest Logic Puzzle Ever recently came to my attention: Three gods A, B, and C are called, in no particular order, True, False, and Random. True always speaks truly, False always ...
1
vote
3answers
95 views

Remove duplicates from sorted array, in place

I solved this problem: Given a sorted array nums, remove the duplicates in-place such that each element appears only once and return the new length. Do not allocate extra space for another array, ...
5
votes
2answers
93 views

Advent of Code 2018 Day 4 - Pythonic Sleepy Guards

Introduction I'm using Advent of Code 2018 to learn Python better, interested in the new type support for Python 3.7, I decided to go with that. Here is my solution to Advent of Code Day 4, both ...
5
votes
2answers
201 views

Size of the largest connected component in a grid in Python

Given an R x C grid of 1s and 0s (or True and False values), I need a function that can find the size of the largest connected ...
2
votes
1answer
77 views

String reversing x times

Inspired by CodeWars We have a string s Let's say you start with this: "String" The first thing you do is reverse it: "gnirtS" Then you will take ...
2
votes
1answer
131 views

LeetCode #28 - Boyer Moore string matching algorithm

The following code implements the Boyer Moore string matching algorithm. The algorithm is used to find a sub-string (called the pattern) in a string (called the text) and return the index of the ...
2
votes
2answers
78 views

Write in file the n-th term in iccanobiF series

Siruri2 | www.pbinfo.ro Fibonacci, a famous Italian mathematician in the Mediaeval Era, had discovered a series of natural numbers with multiple applications, a string that bears his name: <...
4
votes
1answer
75 views

Sport Cards Task

The task: You will receive several input lines in one of the following formats: "{card} - {sport} - {price}" ...
1
vote
1answer
30 views

Merge Two Sorted Lists by splicing together the nodes of the first two lists

I solved this problem: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. How can I improve its execution ...
3
votes
2answers
201 views

Remove all occurrences of an element from an array, in place

I solved this problem: Given an array nums and a value val, remove all instances of that value in-place and return the new ...
3
votes
0answers
151 views

Design an object oriented parking lot

I solved this system design interview question. The problem description Design a parking lot Constraints and assumptions What types of vehicles should we support? Motorcycle, ...
0
votes
1answer
40 views

Search insert position

I am trying to solve this problem: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. and ...
1
vote
1answer
46 views

Find two numbers with target sum

I am trying to solve this problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target. and this is my implementation: ...
1
vote
2answers
43 views

List of Happy Numbers in scala

Definition of Happy numbers taken from Wikipedia. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits ...
7
votes
2answers
571 views

Balanced centrifuge configurations

Given an input N as the size of a centrifuge, I need to find out the number of balanced configurations. The full description is here. Centrifuge is a piece of ...
3
votes
2answers
75 views

Project Euler #7: Nth prime number

I was solving Project Euler #7 on Hackerrank but for two cases, execution time is more than 2 sec. Can you help with optimizing? I'm new to programming. ...
2
votes
1answer
154 views

HackerRank: Fraudulent activity notification

I wanted to get some constructive feedback on my solution to the Fraudulent Activity Notification problem from HackerRank: HackerLand National Bank has a simple policy for warning clients about ...
3
votes
1answer
56 views

Rotate the sub-list of a linked list from position M to N to the right by K places

Given a linked list and two positions m and n. The task is to rotate the sub-list from position ...