Questions tagged [programming-challenge]

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

Filter by
Sorted by
Tagged with
2 votes
3 answers
409 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 ...
  • 125
1 vote
1 answer
95 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 ...
3 votes
3 answers
95 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 ...
  • 287
1 vote
1 answer
75 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 '...
  • 249
-1 votes
1 answer
66 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 ...
  • 101
3 votes
1 answer
74 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 ...
4 votes
3 answers
109 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)....
  • 73
2 votes
2 answers
105 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. ...
  • 21
3 votes
0 answers
132 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 ...
  • 918
4 votes
3 answers
129 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: ...
  • 43
0 votes
0 answers
29 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 ...
  • 101
0 votes
1 answer
333 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 ...
  • 47
0 votes
1 answer
93 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 ...
  • 127
0 votes
1 answer
202 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. ...
  • 505
1 vote
2 answers
129 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 ...
5 votes
1 answer
74 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 ...
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 ...
2 votes
1 answer
150 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 ...
  • 123
6 votes
2 answers
767 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
70 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. ...
  • 300
4 votes
1 answer
208 views

Leetcode, longest palindromic substring

Here's a link Given a string s, return the longest palindromic substring in s. A string is called a palindrome string if the reverse of that string is the same as the original string. Example 1: ...
1 vote
2 answers
185 views

Find the cheapest flight to reach from source to destination

As the input you get the flight schedule as an array, each element of which is the price of a direct flight between 2 cities ...
  • 133
1 vote
1 answer
115 views

Leetcode 55. Jump Game solution

I was working on Jump Game problem on leetcode Question You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your ...
  • 189
6 votes
1 answer
302 views

HackerEarth challenge: Lunch boxes

I was solving the lunch boxes problem on HackerEarth but as I submitted my solution most of the test cases were passed and the rest showed 'Time Limit Exceeded'. I would be very grateful if you could ...
3 votes
3 answers
401 views

Creating Phone Number challenge from Code Wars

I solved a question on Codewars about creating a phone number: Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone ...
  • 127
2 votes
1 answer
107 views

LeetCode#494 target sum (dart is slower than python)

I'm trying to solve a LeetCode problem target-sum, in two languages: Python & Dart. The difference of time taken is shocking for me" Python took ~70ms while Dart took ~900ms !! Why does Dart ...
2 votes
1 answer
91 views

An evolutionary algorithm written in Java to crack an XOR cipher

Alright. So TryHackme is a website that tries to teach hacking with hands on labs. They have a room called JVM Reverse Engineering where the user gets to reverse engineer Java apps, and in particular ...
  • 101
5 votes
1 answer
190 views

Connecting ropes with minimum cost

Question: There are given N ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. The task is to connect the ropes ...
3 votes
0 answers
84 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 ...
5 votes
2 answers
969 views

Find the best couple of an array in 1.5 seconds

I faced this exercise. Given a sequence \$S\$ (\$2 <= |S| <= 10^6\$) of numbers (\$1 <= S_x <= 10^7\$), determine \$max(abs(S_i - S_j) + abs(i -j))\$. Here is the solution I found: ...
2 votes
0 answers
483 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 ...
3 votes
2 answers
234 views

Euler Project: Sums of Digit Factorials

MY CODE: ...
-1 votes
1 answer
56 views

Sum of differences between products and LCMs

I've been trying to solve this Codewars problem https://www.codewars.com/kata/56e56756404bb1c950000992 In this kata you need to create a function that takes a 2D array/list of non-negative integer ...
5 votes
2 answers
406 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 ...
2 votes
1 answer
50 views

Small typesafe assertion library, is()

I need to write a function with the following requirements (Programming TypeScript book by B. Cherny, Chapter 4, exercise 5): Implement a small typesafe assertion library, ...
4 votes
2 answers
602 views

Hangman Game: Revealing guessed letters

I solved this problem: the Edabit Hangman Game challenge. Create a function that, given a phrase and a number of letters guessed, returns a string with hyphens - ...
  • 127
6 votes
2 answers
110 views

LeetCode 126: Word Ladder II -- Memory limit exceeded

I am trying to solve LC126, and got a memory limit exceeded for the following solution. I've seen the answer here -- so I'll try to use Dijkstra as well, but I would like to understand why I get the ...
  • 300
4 votes
2 answers
147 views

Project Euler #51: "Prime digit replacements" in Rust

Problem: https://projecteuler.net/problem=51 "Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime ...
  • 449
6 votes
2 answers
461 views

Codeforces #806 Problem D: Double Strings

I tried solving the following problem by following the suggested approach to solving the problem in the problem tutorial. However, the online judge still says my solution exceeds the time limit. Is ...
  • 61
1 vote
2 answers
175 views

Coin Change in Java

Inspired by a leetcode exercise, I wrote my own coin changer: You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of ...
  • 2,581
4 votes
1 answer
108 views

Decibinary for xth number (Python code)

I created the code for the problem description below. It works for \$N\le10^6\$ but after that it gives a time out error. What I don't understand is how to optimize the code using dynamic programming. ...
4 votes
1 answer
108 views

Time limit error in 'The Minion Game' using python in Hacker Rank

This is the question link for the quick reference. Problem : There are two players Kevin and Stuart have to play a game in which they're pleased to create multiple strings and will get +1 score for ...
4 votes
2 answers
353 views

Geektrust coding challenge: simulating a marketplace for loans

This is the my solution to a coding challenge in Geektrust. The question is linked here. A shortened version would be as follows. The aim is to simulate a marketplace for banks to lend money to ...
  • 43
3 votes
2 answers
142 views

Leetcode 14. Longest Common Prefix beats only ~50% of C++ solutions

The task is to find the longest common prefix. While I had no trouble to find the solution, I'm interested in the statistics of my code: Runtime: 7 ms, faster than 56.36% of C++ online submissions ...
0 votes
1 answer
82 views

duplicate an open file descriptor [closed]

My program implements a function similar to `dup2'. I would like you to please find any problems with the code and what I could improve. code: ...
4 votes
2 answers
95 views

Partition List in 2 parts

I came up with the following code while trying to solve the Leetcode partition list problem Though my solution is accepted, I am not happy with a few of the additional variables which I am creating. ...
  • 169
4 votes
2 answers
195 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
220 views

MP3 Playlist Class in Python

Background Info I am an intermediate level Python programmer. This is my implementation of a MP3 Playlist class challenge that was hosted on 101 Computing.Net. The ...
  • 161
4 votes
1 answer
145 views

Python program for the Longest Substring Without Repeating Characters

I write my Python program below for this Leetcode problem: Given a string s, find the length of the longest substring without repeating characters. Example 1: ...
4 votes
3 answers
2k views

Split word based on terms from an array

I was faced with a coding challenge and I'm looking for a more elegant way to achieve the goal. The challenge Take the word baseball from the first item in the string array and split it into two ...

1
2 3 4 5
65