Questions tagged [programming-challenge]
Use this tag when the code is a solution to a programming challenge. Always include a sufficient description of the problem to be solved - while a link to the challenge is welcome, the review request needs to be complete when the challenge site is unavailable.
3,394 questions
2
votes
3
answers
1k
views
LeetCode 3542: Minimum Operations to Convert All Elements to Zero
I am working on this LeetCode problem where I have to count the minimum number of operations to make all elements in an array equal to zero 3542. Minimum Operations to Convert All Elements to Zero
...
4
votes
2
answers
509
views
Finding a sequence of xors to change a to b
I'm resolving a problem from CodeForces: C. Beautiful XOR. This is what the code is supposed to do:
You have two numbers a and b.
You must transform a into b using XOR operations (...
5
votes
5
answers
1k
views
Check whether a binary tree is symmetric
I implemented a recursive solution that compares the left and right subtree in mirrored fashion. It works for my test cases, but I would like to know if there are any best practices that would make ...
0
votes
3
answers
222
views
C# quicksort implementation (LeetCode Sort an Array)
I implemented quick sort after merge sort as part of LeetCode question for sorting an array. The solution code can be found at https://leetcode.com/problems/sort-an-array/solutions/7180269/i-...
4
votes
3
answers
452
views
FOLLOW-UP to the Strength of a Pyramid Top post with a revised code example
As a follow-up to my previous question, I've decided to post a follow-up question with a revised code that accommodates most of the inputs from the previous question's comments, namely:
Used ...
5
votes
3
answers
570
views
Strength of a Pyramid Top
I need to solve the following competitive programming problem from coderun.ru:
Strength of a Pyramid Top
The pyramid consists of n horizontal layers of blocks: the first layer contains n blocks, the ...
7
votes
4
answers
1k
views
Project Euler #909: L-Expressions I
I am trying to solve the 909th challenge of Project Euler. It is basically about replacing specific patterns in a string until no pattern is found. A given string like ...
5
votes
2
answers
409
views
Wordsearch Generator (Tracking Success/Failure)
I'm creating a wordsearch generator that takes a list of words and outputs a 10x10 grid (2D array) of letters. This is roughly how it works:
loop over words
use boolean ...
3
votes
2
answers
252
views
Third way to place queens and rooks with the higher score (extension of the queen problem)
Here is a third implementation, the second is in my question Place queens and rooks with the higher score (extension of the queen problem) and an initial one is in my answer for the question N queen ...
4
votes
1
answer
196
views
Place queens and rooks with the higher score (extension of the queen problem)
This is a continuation of the question N queen problem-like (+rooks and a different goal) written by someone else, where I answered.
EDIT I continued to work on the subject and a third implementation ...
5
votes
3
answers
1k
views
Project Euler Problem #1: Multiples of 3 or 5
Project Euler Problem #1
Multiples of 3 or 5 states:
If we list all the natural numbers below 10 that are multiples of 3 or
5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of ...
6
votes
2
answers
459
views
(Codewars) Goldbach's Conjecture (by @rsalgado) in Ruby
Link to kata: linkRank: 6 kyuKata author: @rsalgado
I have been recently learning Ruby-lang and have been attempting to solve the following kata from Codewars involving Goldbach's Conjecture:
...
6
votes
2
answers
732
views
Weather Observation Station 8 query
Here's my (correct) solution to a HackerRank question:
Weather Observation Station 8
Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last ...
6
votes
1
answer
593
views
Substring = Permutation of a given pattern
I am working on a problem on LeetCode.
Considering only lowercase characters from 'a' to 'z', I have written some Java code to check if a permutation of a given pattern is a substring of a given ...
1
vote
1
answer
178
views
FreeCodeCamp todo list
I'm writing JS for the FreeCodeCamp todo list; the corresponding HTML and CSS for this can be found on their page. I have made one edit to the HTML - the button with type "submit" has been ...
4
votes
1
answer
119
views
Efficient way to win points in chocolate bowl game
I'm working on an optimization problem involving a turn-based chocolate-sharing game, and I need help optimizing my current brute-force solution.
Problem Description:
You and your friend take turns ...
7
votes
1
answer
117
views
.net core web API simple app with one endpoint
I am trying to complete a challenge - a simple .net core API with one simple endpoint. This endpoint should validate the user's information
and return a unique ID. He should provide: 1) Name, 2) ...
5
votes
2
answers
229
views
LeetCode Number 416: Partition Equal Subset Sum
Problem: MLE
I am confused as to why the LeetCode judge reports Memory Limit Exceeded when my solution looks close to the editorial solution. I not too familiar with ...
7
votes
4
answers
996
views
Project Euler #54: class for poker hands
I'm working right now on Project Euler problem 54, and I figured that this was the perfect opportunity to try to work with classes. This is my first time, so I'm sure that there are a lot of style, ...
7
votes
5
answers
2k
views
Solving an easy LeetCode "Merge Strings Alternately"
I am a C++ dev trying to solve problems in C to practice it, specifically the LeetCode Merge Strings Alternately problem:
You are given two strings word1 and word2. Merge the strings by adding ...
6
votes
2
answers
326
views
(HackerRank) Project Euler+ #250: 250250
Link to problem: linkNumber of solvers: 27 out of 844Solve rate (per person): 3.199%Success rate (over all submissions): 1.78%
Project Euler+ on HackerRank is basically supposed to be a generalization ...
5
votes
3
answers
1k
views
LeetCode 678: Valid Parenthesis String, Recursion memoization to DP
How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution?
The code is working, but I want to improve it.
The challenge I am facing is ...
8
votes
5
answers
1k
views
LeetCode 977: Squares of a sorted array, maintaining non-decreasing order
I tried solving the LeetCode question like many others, trying to incorporate the O(n) time complexity requirement.
Squares of a Sorted Array
Given an integer array ...
8
votes
2
answers
282
views
Leetcode 93: Restore IP Addresses (C version)
This is posted in response to this request made in a discussion of my "C-ish" answer to a recent Code Review question regarding a Python solution to a Leetcode challenge. It was reported ...
11
votes
4
answers
2k
views
Leetcode 93: Restore IP Addresses
(Source: Leetcode 93: Restore IP Addresses [Medium])(Topics: [String] [Backtracking])
The problem is as follows:
Definition: A valid IP address is defined to consist of exactly four integers ...
5
votes
2
answers
427
views
Rust implementation of Euler problems
I'm starting to learn rust and figured my first simple project would be to solve some of the Euler problems. I'd appreciate if anyone could tell me where I might be ...
3
votes
2
answers
196
views
Pattern Finding In Lists of Strings (2d Char Array), Advent of Code Day 04 Solution
This is part 2 of Day 4 of 2024's AoC: The problem is as follows:
It's an X-MAS puzzle in which you're supposed to find two MAS in the shape of an X. One way to achieve that is like this:
...
6
votes
5
answers
896
views
Bracket matching - Advent of Code 2021 Day 10
The following code solves Advent Of Code 2021 Day 10.
The goal for this time around is evaluating whether a line of brackets
is complete, has a syntax error or is missing some closing brackets.
...
5
votes
2
answers
987
views
LeetCode 3366: Minimum Array Sum - w/o DP/memoisation
This program tried to solve LeetCode problem 3366: Minimum Array Sum.
It fails for k odd, op1+op2 high enough such there are more odd value to optionally subtract k from than subtractions to allot.
A ...
3
votes
1
answer
108
views
Advent of Code 2024 - Day 1 (Common Lisp)
I have recently started learning lisp by reading ANSI Common Lisp, and I thought advent of code would be good for practice. Any feedback on my code for Day 1 would be appreciated.
...
4
votes
1
answer
120
views
LeetCode Rust solution for the Sliding Puzzle problem #773
Here is the solution to the LeetCode Sliding Puzzle Problem #773. The problem is to find the shortest solution for a 3 x 2 sliding puzzle.
I would appreciate any ideas to improve this code. But it's ...
6
votes
1
answer
112
views
LeetCode Rust solution for the Flip Columns problem #1072
Here is the solution to LeetCode Problem #1072.
The problem is to find the maximum number of rows in a matrix where all the values can be made equal after some columns are flipped. It's assumed that ...
8
votes
2
answers
892
views
Basic C++ implementation of linux wc command
I am working on the Build Your Own wc Tool coding challenge in C++. I have a working implementation that seems to match the output of the wc command for different ...
4
votes
1
answer
183
views
Poker Lite (AOC 2023 Day 7) using structs wrapped in an enum
I've been trying to learn Rust by working through Advent of Code 2023, specifically for day 7, part 1, here. It's Poker Lite:
You're given a list of hands. The input is formatted as ...
4
votes
4
answers
479
views
Convert the number formats (Decimal - Hexadecimal - Octal) to Decimal
Problem statement:
Write a program called multi_input.cpp that prompts the user to enter several integers in any combination of octal, decimal, or hexadecimal, ...
3
votes
1
answer
271
views
Roman Numerals Look and Say in rust (BIO 2020 Q1)
I was practicing question 1a of the British Informatics Olympiad 2020 past paper.
The Roman look-and-say description of a string (of Is, Vs, Xs, Ls, Cs, Ds and Ms) is made by taking each block of ...
1
vote
1
answer
297
views
golang - Kth largest element in an array using quick select - time limit exceeded issue
I am trying to solve the following problem in leetcode.
https://leetcode.com/problems/kth-largest-element-in-an-array/description
Given an integer array \$nums\$ and an integer \$k\$, return the \$k^\...
6
votes
1
answer
459
views
FORTRAN90 test suite for Project Euler
The intent of this test file is to go through each of my Project Euler solutions and see if they:
return the correct answer, and
do so in under 60 seconds (unless expected otherwise).
I am using ...
5
votes
1
answer
96
views
Parsing Lists: BIO 2024 Q2
I was practising question 2a of the British Informatics Olympiad 2024 past paper.
In this task you will manipulate lists of integers to create new lists. There are three fundamental lists that you ...
4
votes
1
answer
158
views
Efficient polynomial multiplication in Python
I'm practicing problems for the ICPC competition, and one of the problems requires solving it by using an FFT to compute the product of two polynomials efficiently. Since this is for the ICPC ...
4
votes
2
answers
409
views
BIO 2021 Q3a: Window Dressing (BFS in C++)
I was practicing question 3a of the British Informatics Olympiad 2021 past paper.
A shop is looking to display some boxes (conveniently labelled A, B, …) in their window. There is a
desired order for ...
4
votes
1
answer
149
views
BIO 2021 Q1a: Down Pat
I was practicing question 1a of the British Informatics Olympiad 2021 past paper.
A pat is a single letter or a string of letters which can be split into a left and right string (of at least 1 letter)...
1
vote
1
answer
137
views
Finding the number of distinct decompositions a number has using only repdigits
This is a problem from a previous semester that I am trying to upsolve. I am trying to solve a problem involving the total number of ways of decomposing a number using only repdigits. A repdigit is a ...
6
votes
3
answers
857
views
Finding the Zeckendorf Representation of a Positive Integer (BIO 2023 Q1)
I was practicing question 1a of the British Informatics Olympiad 2023 past paper.
In the Fibonacci sequence each number is generated by adding the previous two numbers in the
sequence. We will start ...
6
votes
1
answer
407
views
String Decryption in C (BIO 2022 Q1)
I was practicing question 1a of the 2022 British Informatics Olympiad past paper.
Each letter in the alphabet can be given a value based on its position in the alphabet, A being 1 through to Z being ...
6
votes
3
answers
926
views
Project Euler 127 - abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
We shall ...
6
votes
2
answers
522
views
Family, felon & fuzz River Crossing challenge
I first saw this challenge when a user posted it to SO about two years ago without a shred of code.
The post's plea, "How do I get started?" meant the user's post didn't survive long on that ...
2
votes
1
answer
71
views
Optimal Extraction of Longest Sorted Sequence from Individually Sorted Bucket Arrays Without Repetitions
Consider a bucket array containing sorted and/or empty buckets, and the goal is to extract the longest possible sequence in sorted order, under the following conditions:
Only one element in each ...
3
votes
1
answer
256
views
Leetcode: Number of Islands - BFS (Queue vs Recursion)
I was playing around with leetcode's Number of Islands.
As per the challenge's description:
Given an m x n 2D binary grid grid which represents a map of '1's
(land) and '0's (water), return the ...
3
votes
2
answers
117
views
Optimizing a Function to Check Pronic Numbers in JavaScript
I've written a function in JavaScript to check whether a given number is a Pronic number. A Pronic number, also known as an oblong number, rectangular number, or ...