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
4
votes
1answer
78 views

Manually formatting numbers in Python

I was working on a little Python challenge that was a bit more difficult than expected: format any non-negative number so 1000 turns into ...
2
votes
1answer
69 views

LeetCode: Queue Reconstruction by Height C#

https://leetcode.com/problems/queue-reconstruction-by-height/ Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers \$(h, k)\$, where \$h\$ ...
9
votes
1answer
342 views

Earliest time frog can jump to the other side of a river in C#. Codility's task

I'm new to C#, I programmed a little in java in the past.I had the two previous exercises reviewed here (permCheck, cyclicRotation, with a 100% score, just like this one), and I'm applying what the ...
3
votes
1answer
70 views

Maze path finder using Depth-First Search algorithm

I'm trying to resolve this kata from CodeWars. Kata exercise You are at position [0, 0] in maze NxN and you can only move in one of the four cardinal directions (i.e. North, East, South, West). ...
6
votes
2answers
225 views

Codility's Permutation Check in C#

I've made a few things in Java, and now I'm learning C#. The code passes the tests with 100% final score. I want to know what things can be improved in my code. Task description A non-empty ...
1
vote
3answers
126 views

Sum the largest five numbers

I'm doing a code-challenge problem: Input The first line consists of an integer T (T ≤ 100) which represents the number of test cases. Each test case consists of ...
2
votes
0answers
68 views

LeetCode: House Robber II C#

https://leetcode.com/problems/house-robber-ii/ You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place ...
4
votes
1answer
142 views

Hacker Rank Climbing The Leaderboard

This has been asked a couple of times but here is my implementation in C++. I have 11/12 solutions completed. The 6th test case which has 200000 intial scores and Alice has even more scores causes my ...
1
vote
1answer
51 views

LeetCode: House Robber I C#

https://leetcode.com/problems/house-robber/ You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping ...
4
votes
2answers
184 views

LeetCode: House Robber III C#

https://leetcode.com/problems/house-robber-iii/ Please review for performance The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "...
4
votes
1answer
69 views

LeetCode: Symmetric Tree C#

https://leetcode.com/explore/interview/card/top-interview-questions-easy/94/trees/627 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For ...
11
votes
6answers
1k views

Pseudo Game of Cups in Python

DESCRIPTION: [Inspired by Chandler's GameOfCups with Joey in "Friends"]. Program gets 5-digit zipcode from user. (Assume user won't make a mistake, and will enter exactly 5 digits). ...
1
vote
1answer
159 views

Recover a secret string from random triplets

Got this problem from Codewars. There is a secret string which is unknown to you. Given a collection of random triplets from the string, recover the original string. A triplet here is defined ...
11
votes
3answers
2k views

Algorithm for competing cells of 0s and 1s

I'm working on a practice algorithm problem, stated as follows: There are eight houses represented as cells. Each day, the houses compete with adjacent ones. 1 represents an "active" house and 0 ...
3
votes
1answer
72 views

Java solution to CodeChef “Surgical Strikes” challenge

I've just recently completed this programming "challenge" called surgical strikes: \$N\$ Indian Air Force fighter planes are located in different bases across the country. Each airbase is described ...
3
votes
1answer
92 views

LeetCode: Time Based Key-Value Store C#

https://leetcode.com/problems/time-based-key-value-store/ Create a timebased key-value store class TimeMap, that supports two operations. ...
6
votes
3answers
1k views

LeetCode: Top K Frequent Elements C#

https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/799 Given a non-empty array of integers, return the k most frequent elements. Example 1: ...
1
vote
0answers
66 views

Recursion to dynamic programming [closed]

I was trying to solve a problem on de-arrangements (Number of partial derangement such that exactly prime number discs are found away from their natural positions? (Any number of non-prime K disks ...
1
vote
1answer
93 views

Check if is it possible to get to a point that is presented by a number [closed]

Problem description from an Iranian online course, translated with the help of Google Translate: Tired of coding, Mehdi has gone on to his childhood games. But because he doesn't know who to play ...
0
votes
2answers
82 views

Project Euler problem #19: counting months that began on Sundays

You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest ...
5
votes
4answers
1k views

Confirm the ending of a string

Challenge: Check if a string (first argument, str) ends with the given target string (second argument, target). This ...
2
votes
1answer
178 views

Project Euler #16 - Sum of all digits of 2^1000

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? ...
6
votes
1answer
60 views

Extract strings from nested array in Perl

Extract the strings from nested arrays in Perl. It prints: a, b, c, d, E ...
5
votes
1answer
140 views

Convert a hex string to base64

I wrote a program that converts a hex-encoded string to base64. It's my solution to the first of the Cryptopals challenges. My main concerns are: Portability. I don't want to rely on implementation-...
2
votes
1answer
95 views

LeetCode - Merging piles of stones

This is a LeetCode Problem You have a pile of stones presented as an array. On each turn you must merge k consecutive piles of stones, starting from any pile you wish. You must continue merging ...
4
votes
1answer
90 views

LeetCode: Merge k sorted lists C#

https://leetcode.com/problems/merge-k-sorted-lists/ Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. ...
4
votes
3answers
130 views

(Project Euler #1) Find the sum of all the multiples of 3 or 5 below 1000

I have decent experience in programming before (mostly C++), but I am very, very, very new to Python, and I decided to try out Project Euler as an exercise. Here's the description of Problem 1: If ...
2
votes
2answers
145 views

Counting block combinations I: Project Euler 114

Problem statement (For more detailed description (including pictures), please, visit the link): A row measuring seven units in length has red blocks with a minimum length of three units placed on ...
4
votes
1answer
104 views

Counting Bouncy Numbers: Project Euler #113

Problem statement: Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468. Similarly if no digit is exceeded by ...
5
votes
4answers
951 views

Project Euler problem #112

Problem statement: Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468. Similarly if no digit is exceeded by ...
2
votes
1answer
80 views

Project Euler 121

The following code solves Project Euler Problem 121. I will quote the description of the problem A bag contains one red disc and one blue disc. In a game of chance a player takes a disc at random ...
8
votes
3answers
479 views

Find the smallest positive integer that is absent from a given array

I made the acquaintance of big-O a couple of weeks ago and am trying to get to grips with it, but although there's a lot of material out there about calculating time complexity, I can't seem to find ...
16
votes
2answers
2k views

Translate English to Pig Latin

This is a program for converting English to the pseudo-language Pig Latin. Not the strictest form of Pig Latin but it most likely will accurately output an argument in Pig Latin. I got the idea from a ...
30
votes
8answers
4k views

Project Euler Problem 45

As a self-teaching Python beginner for almost 4 months, I have mostly been doing online challenges including Project Euler problems. Problem 45 asks: Triangle, pentagonal, and hexagonal numbers ...
5
votes
2answers
110 views

LeetCode: Binary Tree Zigzag Level Order Traversal C#

https://leetcode.com/explore/interview/card/top-interview-questions-medium/108/trees-and-graphs/787/ Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from ...
2
votes
1answer
216 views

Twelve Days of X-mas in Python

Printing the lyrics of "Twelve Days of Christmas" seems to be a fairly popular programming challenge. As I've successfully attempted it, I was wondering if the code can be simplified even further (...
5
votes
2answers
105 views
3
votes
2answers
160 views

LeetCode #494: Target Sum (Python)

Below is my solution to LC #494: Target Sum (given a list of numbers and a target integer, find out how many different ways the numbers can be subtracted from the total sum to result in the target sum)...
7
votes
4answers
2k views

Codewars - Highest Scoring Word

Here is my solution for CodeWars - Highest Scoring Game Given a string of words, you need to find the highest scoring word. Each letter of a word scores points according to its position in the ...
2
votes
3answers
111 views

Counting numbers that are divisible by 3 and can be produced from the digits of a given number

I'm trying to solve this problem from codewars. Problem Given a certain number, how many multiples of three could you obtain with its digits? Suppose that you have the number ...
2
votes
1answer
64 views

Python Method for Text Input from Project Euler

Method Frequently input for problems is given as a 1D or 2D array in a text file. Have knocked out a method to do so, but believe something shorter, clearer and cheaper can be written: ...
3
votes
2answers
100 views

Challenge: MORSE_CODE.PY

Converting words to morse code and vice versa using dictionaries and that's it. ...
7
votes
3answers
606 views

Counting the triangles that can be formed from segments of given lengths

Problem Statement: Given an unsorted array of positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles. ...
4
votes
2answers
95 views

Calculate the rates at which users get stuck at each stage

I completed an algorithm problem just as a personal study, and I can't help but feel like my solution is a bit needlessly complicated, although I can't figure out a better way to do it. Here's the ...
8
votes
5answers
737 views

Expanding powers of expressions of the form ax+b

I solved the following problem: Write a function expand that takes in an expresion with a single, one character variable, and expands it. The expresion is in the form ...
3
votes
1answer
81 views

Convert a Binary Tree to Doubly Linked List

Challenge Link on geeksforgeeks: Binary Tree to DLL Given a Binary Tree (BT), convert it to a Doubly Linked List(DLL) In-Place. The left and right pointers in nodes are to be used as previous ...
6
votes
1answer
154 views

Immediate Smaller Element Time Limit Exceeded

Immediate Smaller Element The code is working fine Code is here. For each element in the array, check whether the right adjacent element (on the next immediate position) of the array is smaller. If ...
3
votes
1answer
111 views

Introduction to Haskell: Validating credit card numbers

I have implemented the introductory challenge of University of Pennsylvania's CIS 194: Introduction to Haskell (Spring 2013) course. I have added the most important information of the problem ...
6
votes
3answers
437 views

LeetCode: Group Anagrams C#

LeetCode: Group Anagrams C# Given an array of strings, group anagrams together. ...
3
votes
1answer
81 views

Forming words that start with consonants and vowels

I am just starting to learn programming. I had already coded some functions and stuff in other languages, and whilst trying to complete this Python challenge Kevin and Stuart want to play the 'The ...