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.

138 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
0 answers
571 views

Kattis problem Amanda Lounges

I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
Brian McCutchon's user avatar
6 votes
0 answers
98 views

Chapter 8 Challenge: Add employee names to a department

The boring but exciting challenge: Using a HashMap and HashSet, create a text interface to allow a user to add employee names ...
lml's user avatar
  • 61
5 votes
0 answers
360 views

Palindrome insertion challenge

Here is my solution to the following Daily Coding Problem challenge Given a string, find the palindrome that can be made by inserting the fewest number of characters as possible anywhere in the ...
MrJoe's user avatar
  • 2,043
5 votes
0 answers
4k 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, ...
thebenman's user avatar
  • 1,148
5 votes
1 answer
4k views

Largest rectangle areas after drawing boundaries

I was asked the following question while trying to get a Hackerrank certificate. I couldn't solve on time but I now completed the solution. Can you please check if my solution seems good? Suggestions ...
Benny Joo's user avatar
4 votes
0 answers
212 views

GeekTrust: Traffic problem - functional programming

First attempt to write functional programming, been following OO paradigm all through my programming journey Please review the code and let me know if any comments and violations of functional ...
HariHaravelan's user avatar
4 votes
0 answers
142 views

LeetCode 1632: Rank Transform of a Matrix in Rust

This is a problem-solving code for LeetCode 1632. Given an \$m \times n\$ matrix, return a new matrix answer where ...
prehistoricpenguin's user avatar
4 votes
0 answers
78 views

Extracting cycles from directed graph with max degree 1 and then performing set cover on cycles

I'm trying to solve P1243E in an efficient manner. The problem in simple words is: Given \$k\$ boxes, \$i\$-th box with \$n_i\$ numbers. All numbers are distinct. We need to select one number from ...
RE60K's user avatar
  • 1,456
4 votes
0 answers
830 views

Kadane's algorithms to leetcode "121 Best Time to Buy and Sell Stock"

I employed the conventional Kadane's algorithms to solve a maximum subarray problem in leetcode Best Time to Buy and Sell Stock - LeetCode Description Best Time to Buy and Sell Stock ...
Alice's user avatar
  • 595
4 votes
0 answers
496 views

Two solutions to leetcode 127.wordLadder

I am working on Word Ladder - LeetCode Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such ...
Alice's user avatar
  • 595
4 votes
0 answers
104 views

Writing Go object code that respects Go guidelines

I'm learning Go and I wrote this for a programming challenge. It is working (building and running) but I feel the code is not what Go code should be: Am I using the ...
Poutrathor's user avatar
4 votes
0 answers
390 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 ...
A. Lindberg's user avatar
4 votes
0 answers
52 views

Texplode KotH controller

I am creating a KotH (King of the Hill) challenge for Programming Puzzles and Code Golf. Other site users will write programs that play Texplode (a version of this game on a square grid). The program ...
wizzwizz4's user avatar
  • 323
4 votes
0 answers
308 views

Advent Of Code 2016 Day 9 Part 1 Solution

This code gives the solution to Part 1 of this question: http://adventofcode.com/2016/day/9 Summary: You have to find the length of the input string after using the markers to duplicate parts of it. ...
Light Drake's user avatar
4 votes
0 answers
141 views

Project Euler #14 in Clojure (finding long Collatz sequence chain)

I'm working on a Clojure implementation for Project Euler #14, which asks for the initial element, under 106, that produces the longest collatz-sequence chain. I'm trying to make use of every ...
WolfeFan's user avatar
  • 166
4 votes
0 answers
114 views

Project Euler #2 in Go

I just learned Go (yesterday in fact) and today I made this solution to Project Euler #2. The problem is to sum the even Fibonacci numbers. My program uses the matrix representation of the linear ...
hacatu's user avatar
  • 462
3 votes
0 answers
66 views

Sum all numbers touching symbols in 2D grid (Advent of Code 2023 Day 3, Part 1)

Please offer suggestions to my below Rust approach for solving AoC 2023 Day 3, Part 1. The code is functionally correct, so I'm interested in understanding how I could have solved it in a more ...
naivedeveloper's user avatar
3 votes
0 answers
146 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 ...
durron597's user avatar
  • 918
3 votes
0 answers
148 views

Finding the number of possible paths in a cave system (Python)

I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...
Oleg Shevchenko's user avatar
3 votes
0 answers
78 views

Advent of Code 2021: day 10- Syntax Scoring

The following code solves day 10 in the advent of code challenge. The goal for this time around is evaluating whether a line of brackets is complete, has a syntax error or is missing some closing ...
N3buchadnezzar's user avatar
3 votes
0 answers
188 views

Advent of Code 2021, Day 3 in Haskell

This is a working solution to today's Advent of Code puzzle, written in Haskell. However, I feel like this solution is not optimal. ...
Scriptim's user avatar
  • 131
3 votes
0 answers
130 views

C++ - Longest Common Subsequence

Link to the Problem Here is my code to compute the length of the longest common subsequence of two integer arrays arr[] and brr[]...
White Tiger's user avatar
3 votes
0 answers
307 views

LeetCode: Stone Game C#

https://leetcode.com/problems/stone-game/ Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones ...
Gilad's user avatar
  • 5,321
3 votes
0 answers
121 views

Performance issue regarding Project Euler #60 in Scheme

I solved Project Euler #60: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 ...
Jay Lee's user avatar
  • 151
3 votes
0 answers
204 views

Smashing two heaviest stones until at most one stone is left - counting number of stone comparisions

Based on this question: Heaviest Stone algorithm time complexity Problem: We have a collection of stones, each stone has a positive integer weight. Each turn, we choose the two heaviest stones and ...
slepic's user avatar
  • 5,437
3 votes
0 answers
387 views

LeetCode 1263: Minimum Moves to Move a Box to Their Target Location ||

I'm posting a follow-up code on this question, which seems to be a version of Sokoban. If you'd like to review, please do so. Thank you for your time! Problem Storekeeper is a game in which the ...
Emma's user avatar
  • 3,517
3 votes
0 answers
125 views

Benchmarking multiple implementations of a Code Kata: queue for the self-checkout tills at the supermarket

I was reading this question: Why is my function timing out when run with a larger data set? And although I couldn't quite grasp the OP's implementation and so didn't feel like answering. I did some ...
slepic's user avatar
  • 5,437
3 votes
0 answers
197 views

Count unique subsequences

I came across this question in a coding competition (Java-restricted) and I got a time-length-exceeded. I am unable to provide a link as the contest is closed now. Can I know how can I optimise this? ...
PRANATHI G's user avatar
3 votes
0 answers
221 views

Longest palindrome code in C# takes time out on LeetCode

I like to request a review of the code below, which is my attempt at answering the question here on LeetCode site. The code passes 43 tests, but it times out on the next one. I copied and ran the test ...
Shahin's user avatar
  • 103
3 votes
0 answers
1k 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 ...
Perplexabot's user avatar
3 votes
0 answers
90 views

Solutions for counting trapped water on islands

There are some exercises about islands and water. I have seen other solutions in Java, but they are developed in procedural style in one-two methods. I tried to develop an object-oriented solution ...
AMURWOLF's user avatar
3 votes
0 answers
114 views

Advent of Code 2017 Day 3 (part 1) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JS only. So I took a problem from Advent of Code. https://adventofcode.com/2017/day/3 You come across ...
thadeuszlay's user avatar
  • 3,993
3 votes
0 answers
119 views

SPOJ Fast Matching challenge

I wrote a solution to the MATCHING challenge on SPOJ: FJ has N (1 ≤ N ≤ 50,000) cows and M (1 ≤ M ≤ 50,000) bulls. Given a list of P (1 ≤ P ≤ 150,000) potential matches between a cow and a bull, ...
kumarmo2's user avatar
  • 271
3 votes
0 answers
366 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
3 votes
0 answers
209 views

Codingame: Great Escape bot in Ruby - Follow-up

This is a follow-up to Codingame: Great Escape bot in Ruby. As mentioned there, my first reasonably sized Ruby project is a bot for CodinGame's Great Escape contest (here is a sample gameplay video). ...
Mangara's user avatar
  • 465
3 votes
0 answers
782 views

Hackerrank: Sherlock and anagram (optimal time complexity)

Problem statement Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings. Input Format First line contains \$T\$, the number of testcases. Each testcase ...
Jianmin Chen's user avatar
  • 2,396
3 votes
0 answers
231 views

Finding the maximal bottleneck in a 2D matrix from source to destination

I recently started solving programming challenges and this one is causing me performance trouble. The problem statement is the following: You are given a 2d matrix where each cell contains an ...
tricktron's user avatar
3 votes
0 answers
673 views

Hackerearth Simple Function - Follow-up

Problem statement Let us first describe a SimpleFunction: ...
Jianmin Chen's user avatar
  • 2,396
3 votes
0 answers
1k views

Roman number converter in Kotlin

I'm learning kotlin and java. As a code-kata I wrote the roman to decimal converter. I'd be very grateful for code review. I was trying to keep things simple and funcional. I'd especially appreciate ...
Sebastian Kramer's user avatar
3 votes
0 answers
1k views

Solving the Mining algorithm from HackerRank

I was working on this problem for a few hours last night and finally came up with a brute-force solution. The task is to report the minimum work necessary (sum of weight × distance) to relocate gold ...
jamkin89's user avatar
3 votes
0 answers
410 views

CodeEval - Lucky Tickets challenge

This a solution to the CodeEval's challenge "Lucky Tickets". After a failed attempt with brute-force calculations (no surprise here), I have tried to implement an algorithm that I found on ...
Slyvain's user avatar
  • 131
3 votes
0 answers
196 views

ACM-ICPC HackerRank challenge in C++

I was doing a programming question in C++ at HackerRank. Given a set of up to 500 bitstrings, each up to 500 bits long, the task is to find the pair a and b such that the bitwise OR contains the most ...
Sukhmeet Singh's user avatar
3 votes
0 answers
71 views

Optimizing a problem that test all permutations of 1 array with other fixed array

I'm trying to solve this question on a contest programming judge. Description of the problem: There are N birds in a forest, each in their respective tree. There are N tired crows in this forest, ...
user avatar
2 votes
0 answers
25 views

Last Stone Weight Problem in Haskell Using `fold`

A previous solution of this code has been posted on Code Review before. This solution is more complicated then that one, but more performant (see the below) Why is this another Question instead of a ...
WesAtWork's user avatar
2 votes
0 answers
64 views

Advent of code 2023 day 9: Sequence extrapolation - in pure Bash

Part 1 Today's task involves extrapolating the next value in sequences, given in this format: 0 3 6 9 12 15 1 3 6 10 15 21 10 13 16 21 30 45 The task is to ...
janos's user avatar
  • 111k
2 votes
0 answers
75 views

Advent of code 2023 day 7: Ranking Camel Cards hands - mostly in Bash

Part 1 Today's task is to rank hands in a Camel Cards game and compute the total score. In Camel Cards, you get a list of hands, and your goal is to order them based on the strength of each hand. A ...
janos's user avatar
  • 111k
2 votes
0 answers
41 views

Advent of code 2023 day 6: Count ways to win boat race - in pure Bash

Part 1 To paraphrase the puzzle, given the times and record distances of boat races like this: Time: 7 15 30 Distance: 9 40 200 That is, the first ...
janos's user avatar
  • 111k
2 votes
0 answers
1k views

Determining the winning bingo from a set of bingo boards and sequence of draws

I've learned Python basics about two years ago and did a few personal projects, one big one that turned out to be useful in my line of work, a few small programs for my hobbies and I've also began ...
Oleg Shevchenko's user avatar
2 votes
0 answers
592 views

Cron expression parser

Problem Write a command line application or script which parses a cron string and expands each field to show the times at which it will run. ~$ your-program "*/15 0 1,15 * 1-5 /usr/bin/find"...
CodeYogi's user avatar
  • 5,107
2 votes
0 answers
109 views

Partial Function composability in Haskell

Below is my solution for the CTFP chapter 4 challenges which essentially involves composing partial functions (that don't have defined outputs for all possible inputs i.e. returning a Maybe). The ...
tangy's user avatar
  • 143