Questions tagged [programming-challenge]
Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
3,301
questions
0
votes
1
answer
45
views
Python Logic Gate Circuit Simulator [closed]
I have recently become interested in simulating logic circuits because of a electronics class at school. I have created a functioning simulator for logic gate circuits in Python. My implementation ...
0
votes
3
answers
76
views
Efficient Solution for Finding Product of Largest Pair in Array
Hello fellow developers,
I have written a function called max_product that aims to find the product of the largest two integers in a unique array of positive ...
1
vote
0
answers
18
views
LeetCode 399 Evaluate Division using Scala
In order to gain familiarity with Scala I am trying to solve the following problem
https://leetcode.com/problems/evaluate-division/description/
You are given an array of variable pairs equations and ...
3
votes
3
answers
904
views
Hackerrank: Fraudulent Activity Notifications
I'm having trouble on a question from Hackerrank, this solution works for smaller lists but seems to collapse when the list grows to 200,000 where I get the error "Wrong Solution". The ...
1
vote
1
answer
94
views
Determine the chance a streak of 6 HEADs or 6 TAILS appear in 100 flips, repeated 10000 times [closed]
Here's the problem from the book Automate the boring stuff:
write a program to find out how often a streak of six heads or a streak of six tails comes up in a randomly generated list of heads and ...
5
votes
2
answers
110
views
Generating Pascal's Triangle in C99
I recently completed the Pascal's Triangle challenge on leetcode. I would like to have my code reviewed.
You don't need a leetcode account to see the description of the challenge linked above, but for ...
3
votes
1
answer
249
views
Algorithm Challenge: Fuzzy Search
I recently took part in an algorithm challenge to create a Fuzzy search with the following criteria:
Given a set array, create a function that receives one argument and returns a new array containing ...
4
votes
1
answer
975
views
Given an integer array A and a range, find a subarray within the range with a minimum sum
Problem
HackerRank Range query:
You are given an array A of n integers. You have to perform ...
7
votes
1
answer
680
views
Displaying some multiples
Displaying Some Multiples
Write a program to calculate the multiples of a given number. Have the user enter a number, and then use a for loop to display all the multiples of that number from 1 to 12. ...
4
votes
1
answer
86
views
Find the longest palindromic subsequence - Using a hashmap in Rust
This is a leetcode question which I wanted to solve using Rust as I'm learning Rust at the moment. I would appreciate some feedback on how to write it idiomatically.
Link to the question: https://...
1
vote
2
answers
209
views
Split the Bill and calculate the Tip
I have created a Bill Splitter page that asks for the total bill amount, tip percentage, and the number of people. Then it displays the tip and the total amount (including the tip) each person has to ...
5
votes
2
answers
4k
views
Evaluating a completely parenthesized arithmetic expression
I tried to solve the following problem in a programming challenge, but the verdict was time limit exceeded.
Completely parenthesized expression
Write a program that reads a completely ...
5
votes
2
answers
2k
views
Speedup for Project Euler 44 - pentagon numbers
I'm trying to solve the problems of Project Euler with Haskell within less than 10s with optimized code (ghc -O2). Unfortunately, I'm struggling to find a correct ...
6
votes
1
answer
867
views
Block storage rewrites
Summary
In a block storage system, new data is written in blocks. We are going to represent the flash memory as one sequential array. We have a list of block writes coming in the form of arrays of ...
2
votes
3
answers
448
views
Recursive palindrome check
I'm trying to solve this which basically calls for a recursive palindrome check with some minor extra steps (Special characters and whitespace can be ignored). The test inputs' length can be 100000 ...
3
votes
3
answers
101
views
Solution to Codejam 2021 1C (Closest Pick) in C
The following code is my solution to the Closest Pick problem from Codejam 2021.
You are entering a raffle for a lifetime supply of pancakes. N tickets have already been sold. Each ticket contains a ...
1
vote
1
answer
81
views
Count islands in a binary grid
This is the No of Island code challenge.
Please review my implementation in Haskell. I know there must be some better way of doing this.
Given an m x n 2D binary grid grid which represents a map of '...
3
votes
1
answer
103
views
Validating a Sudoku Board in Python
The problem statement is as follows:
Sudoku is a game played on a 9x9 grid. The goal of the game is to fill
all cells of the grid with digits from 1 to 9, so that each column,
each row, and each of ...
-1
votes
1
answer
69
views
Using JavaScript to interface with REST APIs
The website TryHackMe came up with a challenge that involves using HTTP requests to interface with REST APIs (here, task #14/day 9). The challenge basically involves querying a basic REST API to ...
2
votes
1
answer
127
views
A simple JavaScript function that does prime factorization
This is a simple JavaScript function that does prime factorization.
I wrote it on an Android phone with online editor (I don't have access to computers in night time):
Code:
...
4
votes
3
answers
206
views
Project Euler #2 in F#
Project Euler Problem 2 asks for the sum of all even Fibonacci numbers below 4 million.
My first attempt at this problem using functional programming with F#. I would've liked to use some kind of ...
0
votes
0
answers
187
views
4
votes
3
answers
119
views
Improving efficiency of Rust algorithm ported from Python generator
I'm learning Rust by solving ProjectEuler problems.
To this end, I am trying to port a solution to problem 88 (link) in Python that heavily relies on generators to Rust (which doesn't have generators)....
10
votes
4
answers
1k
views
Wordle puzzle game
I am a beginner programmer with not much experience, the little I do have is with Python specifically.
With all the fuss going around about the popular word game "Wordle" I wanted to ...
1
vote
1
answer
1k
views
HackerRank CountingSort 1 in C#
Comparison Sorting
Quicksort usually has a running time of n x log(n), but is there an algorithm that can sort even faster? In general, this is not possible. Most sorting algorithms are comparison ...
3
votes
0
answers
136
views
Advent of Code 2021 Day 19
I am taking advantage of the recent layoffs to teach myself Kotlin. I am a career Java programmer, I've touched Kotlin before but not actively, and not for a few years. I wrote it all in one file ...
1
vote
0
answers
117
views
Algorithm design for CodeChef - Our Base is Under Attack [closed]
I was working on a CodeChef challenge: Our Base is Under Attack. I have a working solution but it is not fast enough. Could you recommend anything to make it faster?
...
2
votes
2
answers
119
views
Generate the number of partitions of each integer
I've coded a program that calculates the number of partitions of n into at least two distinct parts, and is relatively quick too (about N^1.5 complexity). For input 30 000 it takes roughly 4 seconds. ...
0
votes
1
answer
503
views
sum of intervals kata in codewars
instructions for the kata:
Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only ...
4
votes
3
answers
131
views
Simple photomosaic generator
I wrote an implementation of Robert Heaton's Programming Exercise for Advanced Beginners #4 (photomosaics) in C99 using the MagickCore library. The full code is as follows:
...
0
votes
0
answers
39
views
Modified PoC for BlogEngine.NET CMS (CVE-2019-6714)
This is a modified exploit proof of concept targeting the BlogEngine.NET content management system (CVE-2019-6714) for the .NET framework. I modified it (from Cobb 2019) to execute payloads via ...
7
votes
1
answer
2k
views
Codewars: N-dimensional Von Neumann Neighborhood in a matrix
Task:
For creating this challenge on Codewars I need a very performant
function that calculates Von Neumann Neighborhood in a N-dimensional
array. This function will be called about 2000 times
The ...
1
vote
1
answer
248
views
MSD Radix sort in Place in c++, Object/Pointer Oriented
Memory:O(log(max)base(mod)*mod)Speed:O(log(max)base(mod)*n)
I did a radix sort in place to not get a auxliar array. In the process i discorver a few things.
Is imposible to do LSD radix sort in place ...
3
votes
1
answer
44
views
Generate total property sold for given postcode
I had to implement the below as a coding challenge.
There are two http endpoints. The first http endpoints returns a list of postcodes. The second http endpoint takes a postcode as a parameter and ...
5
votes
6
answers
3k
views
Find largest binary gap of a number N
I have picked up a problem from Codility website and tried to work it out.
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ...
0
votes
1
answer
105
views
Permutations CodeWars problem solved!
i have solved a question in codewars:
https://www.codewars.com/kata/5254ca2719453dcc0b00027d/python
, here's my solution is it unefficient to use itertools because people are blaming that is cheating ...
5
votes
1
answer
76
views
Möbius function using iterators for prime factors
While working on Project Euler, I have come across a few questions involving usage of the little omega function, big omega function, and Möbius function.
My prior code wrote factors into an array and ...
4
votes
2
answers
315
views
Project Euler # 53 Combinatoric selections in Python
There are exactly ten ways of selecting three from five, 12345:
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
In combinatorics, we use the notation, 5C3=10.
In general, nCr = n! / r! (n−r)!, ...
4
votes
2
answers
215
views
Counting primes less than n in Python
I implemented (a refinement of) the Sieve of Eratosthenes for counting primes less than a given number n. This is a coding exercise from LeetCode. The class Solution...
3
votes
2
answers
531
views
Zeckendorf Representation of positive integer
Zeckendorf's theorem states that all positive integers can be represented uniquely as the sum of one or more distinct Fibonacci numbers in such a way that the sum does not include any two consecutive ...
0
votes
1
answer
215
views
Calculate score of rock-paper-scissors (Advent of Code 2022: Day 2)
Advent of code, Day 2.
Here is my code.
Less verbose version of the question follows.
...
2
votes
1
answer
2k
views
HackerRank: XOR-sequence
I am trying to solve the following problem at HackerRank:
XOR-Sequence
An array, \$A\$, is defined as follows:
\$A_0 = 0\$
\$A_x = A_{x-1} \oplus x\$ for \$x>0\$, where \$\oplus\$ ...
1
vote
2
answers
141
views
Implementation of aho corasick algorithm - slow suffix construction
EDIT: Dequeu was the correct guess
EDIT: I did the BFS method for the suffix link/output link construction
I'm doing a hackerrank challenge and I came up with this implementation of the aho corasick ...
2
votes
1
answer
158
views
Finger Exercise: Update book cipher by creating new book
I'm working my way through the finger exercises in John Guttag's book Introduction to Python Programming, third edition. The following finger exercise on page 143 describes encryption/decryption with ...
5
votes
2
answers
421
views
Leet Code 139 (Word Break) using a trie with recursion
I was attempting to solve LeetCode 139 - Word Break
Given a string s and a dictionary of strings wordDict, return
...
8
votes
3
answers
4k
views
Piling Up with Python
This is my solution for a Hackerrank problem. The problem was:
There is a horizontal row of cubes. The length of each cube is given. You need to create a new vertical pile of cubes. The new pile ...
6
votes
2
answers
822
views
Find all combinations of length 3 whose sum is divisible by a given number
I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size.
The problem: Given a list ...
3
votes
1
answer
78
views
Number to Roman in Rust
I solved LC12 (Integer to Roman) in Rust.
I am a beginner with Rust, so I translated my previous solution from C++ to Rust.
I am looking for feedback on how I could improve the following Rust code.
...
11
votes
3
answers
833
views
Print sums of all subsets
Print sums of all subsets of a given set
Problem summary : Print all subset sums of a given set of integers
My approach is to store previous results and use them to calculate new (similar idea as DP).
...
6
votes
2
answers
13k
views
What is the 10001st prime number?
Project Euler problem 7 says:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number?
I believe that my code is ...