Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [programming-challenge]

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

0
votes
0answers
37 views

String Mix Code Wars Kata

Problem Statement Given two strings s1 and s2, we want to visualize how different the two strings are. We will only take into account the lowercase letters (a to z). First let us count the ...
5
votes
3answers
300 views

Python generator for “barely obtuse” triangles (Project Euler 224)

I am trying to solve Project Euler Problem 224: Let us call an integer sided triangle with sides a ≤ b ≤ c barely obtuse if the sides satisfy a2 + b2 = c2 - 1. How many barely obtuse triangles ...
2
votes
3answers
68 views

Stable-sorting all even numbers before odd numbers in a linked list

Given a Linked List of integers, write a function to modify the linked list such that all even numbers appear before all the odd numbers in the modified linked list. Also, keep the order of even ...
-2
votes
0answers
24 views

Project euler problem 23 [on hold]

below is my code, it takes to long to compile, any improvement in the code to make it quickly. ...
3
votes
1answer
69 views

Advent of Code 2018 Day 13 - Detect mine cart collisions

This is a solution to Advent of Code Day 13 (problem specification, test input), for which I was asked to read a layout of tracks and mine carts and detect 1) where the first crash would occur and 2) ...
2
votes
1answer
86 views

Data Transfer Task

The task: You will be given several lines of messages containing data. You have to check for the validity of the lines. A valid line should be in the format: ...
-4
votes
0answers
11 views

SPOJ is giving WA for this solution of ROCK [closed]

I am solving ROCK problem on SPOJ. I dont know why I am getting WA here. Tried many testcases. ...
1
vote
1answer
55 views

Advent of Code 2018 Day 1 in OCaml: Find length of cycles when accumulating deltas

I just started Advent of Code 2018. This is exercise 2 of day 1, and I can't understand why my code is so slow (4 minutes 37 seconds, compared to 200ms for a friend who did it in Clojure with the same ...
2
votes
1answer
56 views

Find all combinations of 4 elements whose sum equals a target in Python

I wrote a solution to find all combinations of 4 elements from a list whose sum of elements equals some target Given an array nums of n integers and an integer target, are there elements a, b, c, ...
2
votes
0answers
45 views

Project Euler #81 in Haskell: minimal path sum through a matrix

I just completed Project Euler Problem 81 in Haskell: In the 5 by 5 matrix below, ...
3
votes
2answers
55 views

Simulation of an alien population

Background I've come across a puzzle (Problem 10 from this list of sample interview questions): One day, an alien comes to Earth. Every day, each alien does one of four things, each with equal ...
1
vote
1answer
63 views

Credit card validator in Python 3.7.1

I am doing some projects so I can teach myself programming. The one that I finished states: "Credit Card Validator - Takes in a credit card number from a common credit card vendor and validates it to ...
9
votes
2answers
145 views

Project Euler #119 : Digit power sum

From problem #119 of the Project Euler : The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number ...
3
votes
5answers
672 views

Project Euler 92: count sum-squared-digits chains that reach 89

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1 85 → 89 →...
1
vote
2answers
50 views

Recursive range iteration

I decided to do Advent of Code this year in D, and the following is my solution to day 8. Algorithm aside, I was specifically wondering if there was a better way to use ranges in a recursive manner ...
3
votes
4answers
98 views

Count combinations of positive and negative that sum to target number

The problem I'm solving is given as follows: You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and <...
2
votes
2answers
55 views

Project Euler #10 (sum of primes less than two million) in Clojure

I'm new to Clojure and using some Project Euler problems to familiarize myself with the language's capabilities. Problem #10 asks to find the sum of all primes less than two million. I wanted to ...
1
vote
0answers
35 views

Maximize product of sum of subsequences [closed]

Code Chef Problem description You are given a sequence of \$N\$ powers of an integer \$k\$; let's denote the \$i\$-th of these powers by \$k^{A_i}\$. You should partition this sequence into two ...
2
votes
1answer
48 views

Program finds the first almost matching string in a list - Advent Of Code 2018 Day 2 Part 2

Advent of Code 2018, day 2, part 2: The [two IDs you are looking for] differ by exactly one character at the same position in both strings. For example, given the following IDs: ...
2
votes
1answer
213 views

Advent of Code 2018 day 1 part 2: find the first aggregated number that occures twice

I am using the coding puzzels of https://adventofcode.com for improving my F# skills. Problem: Day 1 Part 2: Starting with frequency 0, a list of numbers should be added successive generating new ...
2
votes
3answers
179 views

Leetcode #91 - Number of ways to decode a string

I'm working on problem 91 on Leetcode.com called Decode Ways and I've successfully managed to get a working recursive solution but it results in Time Limited ...
3
votes
1answer
91 views

Find the length of a frequency-change cycle (Advent of Code 2018)

I tried to do the second part of the 1. December challenge of Advent of Code in Haskell. I'm fairly new to Haskell but I have plenty of experience in other (procedural) languages. I struggled with the ...
6
votes
1answer
1k views

Advent of Code 2018 day 1 part 2: find the first repeated number after some increases and decreases

Here is the problem: Part Two You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice. ...
3
votes
2answers
70 views

Parallel processing simulation

Input n number of workers and m jobs to be scheduled, followed by m lines of time ...
2
votes
2answers
66 views

Given some integers, find triplets where the product of two numbers equals the third number

I am trying to solve a coding challenge: Given N integers A1, A2, …, AN, count the number of triplets (x, y, z) (with 1 ≤ x < y < z ≤ N) such that at least one of the following is true: ...
5
votes
2answers
77 views

Tick-tack-toe (Jumping into C++)

The exercise is from Alex Allain's book "Jumping into C++". From Chapter 10 Practical Problem 4: Write a small tic-tac-toe program that allows two players to play tic-tac-toe competitively. ...
-1
votes
0answers
23 views

Calculate number of possible messages from a coded string

Question Alphabets are assigned numbers like - a = 1 b = 2 c = 3 . . z = 26 Given a number like 1234 as input calculate count ...
0
votes
1answer
33 views

Function that adds two items from a list in search of those that will match some given sum

I'm doing a Daily Challenges to get better with Python. I completed the first challenges with a working code but I want to make sure if there's anyway to improve or optimize it. I have a function ...
2
votes
2answers
37 views

Project Euler #4 - Finding the largest palindrome that is the product of two three-digit numbers.

This is my attempt at the 4th problem on Project Euler: ...
3
votes
1answer
94 views

“Counter Game” Powers of 2 Game

I have been working on this hackerrank problem: Louise and Richard have developed a numbers game. They pick a number (1 ≤ n < 264) and check to see if it is a power of 2. If it is, they divide ...
5
votes
1answer
377 views

Find the smallest positive number missing from an unsorted array

this is the original question https://www.geeksforgeeks.org/find-the-smallest-positive-number-missing-from-an-unsorted-array/ You are given an unsorted array with both positive and negative elements....
2
votes
1answer
43 views

Find palindromes in circular rotated string

I'm trying to tackle a programming challenge to determine how many palindromes exist in a given string that is being rotated character by character. My solution works, but it's too slow, and I'm ...
1
vote
1answer
92 views

Minimum Area Rectangle in Swift

This is my solution to LeetCode – Minimum Area Rectangle in Swift 939. Minimum Area Rectangle Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these ...
2
votes
1answer
65 views

Valid Sudoku in Swift

This is my solution to LeetCode – Valid Sudoku in Swift. ...
1
vote
2answers
75 views

String Compression

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string "aabcccccaaa" would become "a2b1c5a3". If the "compressed" string ...
5
votes
1answer
44 views

Repeated Strings Hacker Rank challenge

I'm doing a hacker rank challenge with this one called "Repeated String". I attempted this challenge in my weaker language java. The goal is to print out the occurrences of the letter a. First you're ...
-3
votes
1answer
39 views

How to reduce run time of my code to solve Cycle race practice problem from geeksforgeeks

I am referring to this problem https://practice.geeksforgeeks.org/problems/cycle-race/0. The Problem description: Jack and Jelly are two friends. They want to go to a place by a cycle ( Assume that ...
2
votes
2answers
73 views

Hacker Rank: Counting names with prefix matches using a trie

Practicing hacker rank questions and would love some feedback on how I could perform optimizations on a Trie. This code will add a bunch of names into a trie and then when asked will turn how many ...
1
vote
2answers
77 views

Calculating triangular numbers

A triangular number is a product of three factors as follows: $$ \text{Triangular number} = x(x + 1)(x + 2) $$ Is there a way to make this code faster? As it is the code calculates every triangular ...
2
votes
1answer
33 views

Leetcode #826. Most Profit Assigning Work solution in Java (Sort + Binary Search)

Problem Statement: We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job....
4
votes
1answer
46 views

Euler Problem 7 (finding the 10001st prime) in Powershell

I am having issue making this code more efficient. The problem to be solved is as follows: By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. ...
4
votes
3answers
59 views

Print the first, last, and in-between integers of a range

Given our spec from Code Golf: Given two integers, output the two integers, and then the range between them. The order of the range must be the same as the input. Examples: ...
1
vote
1answer
47 views

Project Euler #49: Find 12-digit number concatenating a three terms sequence

First of all, project Euler has been a great help for me to learn Clojure. I tried for months trying to get web projects going but ended up frustrated with and struggling with tooling and libraries ...
0
votes
2answers
41 views

Incrementing specified list values, with “catch-up” [closed]

I completed a coding challenge recently in which my function was to be given two parameters: N, the number of counters to be used (numbered 1 through N) - and A, an array of integers. Iterating ...
4
votes
3answers
1k views

Bitmasking and searching consecutive 1's

I have written code to count the continuous ones in an array or you can use binary string for convenience. Any solution using the binary string is acceptable. My Solution is: ...
3
votes
2answers
55 views

Contest Solution: Remorseful Sam

The Problem Sam Morose served for many years as communications officer aboard the U.S.S. Dahdit, a U.S. Coast Guard frigate deployed in the South Pacific. Sam never quite got over the 1995 ...
2
votes
1answer
68 views

Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)

Problem Statement Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
1
vote
1answer
66 views

Contest Solution: Al Gore Rhythm

The Problem After his brush with the Justice Department over fundraising with Buddhist monks, the Vice President devised a plan to ensure that such activities are carried out in a more discrete ...
1
vote
2answers
43 views

Contest Solution: Super Freq

The Problem A character is known to its homeboys as a super freq if it occurs with frequency greater than 15% in a given passage of text. Write a program that reads an ASCII text file and ...
1
vote
1answer
57 views

Contest Solution: Packet Sniffer

The Problem Sniffed any good packets lately, dude? Hopefully you haven’t done this illegally, but rest assured that there are some who have. If you surf the Internet, you have probably visited ...