The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [programming-challenge]

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

131 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
1k views

Deepest pit of an array

Following is based on a problem description from a Codility test, as a task in an interview. DeepestPit - problem description A non-empty zero-indexed array B ...
2
votes
0answers
78 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, ...
2
votes
0answers
124 views

Solo dice game (from Reiner Knizia’s Decathlon)

I'm trying to implement Reiner Knizia’s Decathlon, a set of 10 solo dice games played with 8 dices named after Decathlon events in Olympics. The first event is called "100 Metres". The player divides ...
2
votes
0answers
295 views

HackerRank Attribute Parser

I wrote a program for solving the Attribute Parser challenge on HackerRank. The challenge is to read some specified number of lines of HTML-like markup (each line no more than 200 characters; for any ...
2
votes
0answers
942 views

Logistic Regression using PyTorch

I want to get familiar with PyTorch and decided to implement a simple neural network that is essentially a logistic regression classifier to solve the Dogs vs. Cats problem. I move 5000 random ...
2
votes
0answers
482 views

Three sum using binary search

Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
2
votes
0answers
246 views

Project Euler #4 Python while loop efficiency

The problem statement for Project Euler Problem 4 is as follows: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99....
2
votes
0answers
133 views

Advent of Code 2017 Day 6 (part 2) 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 (the 2nd part of Day 6). You can only access the 2nd part ...
2
votes
0answers
111 views

Leetcode: divide without multiplication, division, and mod operator

I am new to this and would like to know some basic tips to make my coding more efficient, because on this question my code is obviously not efficient enough for the practice problem and I looked in ...
2
votes
0answers
460 views

Leetcode 10: Regular Expression Matching

Problem statement Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching ...
2
votes
0answers
244 views

Learn trie through Leetcode 212

Problem statement: Given a 2D board and a list of words from the dictionary, find all words in the board. Each word must be constructed from letters of sequentially adjacent cell, where "...
2
votes
0answers
318 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 ...
2
votes
0answers
599 views

Hackerrank: Max Score

Problem statement Consider an n-element sequence of integers, A = {a0, a0, ..., an-1}. We want to perform \$n\$ operations on \$A\$, where each operation is defined by the following sequence of ...
2
votes
0answers
1k views

Leetcode 317: Shortest distance from all buildings

Problem statement: You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. You are given a ...
2
votes
0answers
64 views

2016 Advent of Code Day 2, Part 1 and Part 2

Continuing from yesterday, here's a simple solution in C to part 1 of Advent of Code Day 2. I used a simple state machine to map from each keypad key to the next keypad key given the input. ...
2
votes
0answers
396 views

HackerRank university codesprint array construction

Problem statement Professor GukiZ has hobby — constructing different arrays. His best student, Nenad, gave him the following task that he just can't manage to solve: Construct an \$n\$-...
2
votes
0answers
1k views

HackerRank - Matrix Rotation

Problem statement Given a matrix (up to 300 × 300), rotate each element R steps anti-clockwise along concentric rectangular paths (R up to 109). The algorithm is rated as hard on HackerRank. On ...
2
votes
0answers
264 views

GSS4 - Segment Tree implementation 2

The problem is also known as GSS4. The exact detail can be seen here but I reached TLE. You are given a sequence A of N(N <= 100,000) positive integers. There sum will be less than \$10^{18}\$....
2
votes
0answers
496 views

Hackerrank Simple Text Editor in Swift

I solve this problem in Swift. However, some cases I got terminated due to timeout because the solution isn't efficient enough. I did check the solutions and they are correct. Any tips on making it ...
2
votes
0answers
344 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 ...
2
votes
0answers
356 views

Implementation of the Minimum Stop Algorithm in Javascript

I started taking the Algorithm design class from Coursera. So into the third week they talk about Greedy algorithms and walks through a sample problem. This is the Problem Statement that I could find ...
2
votes
0answers
3k views

Solution to King Kohima problem in Python

King Kohima problem: King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to ...
2
votes
0answers
2k views

HackerRank: XOR-sequence

I am trying to solve the following problem at HackerRank: XOR-Sequence An array, \$A\$, is defined as follows: \$A_0 = 0\$ \$A_x = A_{x-1} \oplus x\$ for \$x>0\$, where \$\oplus\$ ...
2
votes
0answers
568 views

“Partial solution” on Code Eval for Clojure FizzBuzz

I'm just getting started on the site CodeEval, and I submitted my first solution today. What I don't understand is why it's marking my (working) answer as only a "partial solution". The site doesn't ...
2
votes
1answer
412 views

Cut Off Trees for Golf Event LeetCode challenge

I solved this LeetCode Challenge: You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-negative 2D map, in this map: 0 represents the obstacle can'...
1
vote
0answers
22 views

LeetCode: Daily Temperatures C#

https://leetcode.com/problems/daily-temperatures/ Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until ...
1
vote
0answers
129 views

LeetCode: critical connections in a network C# (Tarjan's algorithm)

https://leetcode.com/problems/critical-connections-in-a-network/ Please review for memory and runtime performance. There are n servers numbered from 0 to n-1 connected by undirected server-to-...
1
vote
0answers
38 views

Codility's GenomicRangeQuery solution in C#

I've been learning C# for a few months now, and I've done some basic things in java last year. I made a solution for the problem the title states, this is the task description. Task description ...
1
vote
0answers
81 views

Custom Knight dialer solution's time and space complexity

I recently solved the Knight Dialer problem but I'm not quite sure if I got the time complexity right; hence I'm requesting the following: 1) Time and space complexity review and explanation on why ...
1
vote
0answers
56 views

Algorithm X implementation for Minimum Dominating Set

As as final project for a MOOC I wanted to write a program that finds the exact cover set/minimum dominating set from the given social network data. So I did end up with writing this. I kinda followed ...
1
vote
0answers
49 views

Project Euler # 42 Coded triangle number in Python

The nth term of the sequence of triangle numbers is given by, \$t_n = \frac{n(n+1)}{2}\$; so the first ten triangle numbers are: ...
1
vote
0answers
47 views

Project Euler # 38 Pandigital multiples in Python

Take the number 192 and multiply it by each of 1, 2, and 3: 192 × 1 = 192 192 × 2 = 384 192 × 3 = 576 By concatenating each product we get the 1 to 9 pandigital, 192384576. We will ...
1
vote
0answers
23 views

Project Euler # 28: Number spiral diagonals in Python

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: ...
1
vote
0answers
52 views

Graph-coloring solution using depth-first search

I'm trying to solve this question: Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n ...
1
vote
0answers
514 views

Shortest way to form a string out of a subsequence of a string

The task is taken from LeetCode - From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). Given two strings source and target,...
1
vote
0answers
133 views

LeetCode: trapping rain water C#

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by array [...
1
vote
0answers
62 views

Merge k Sorted Lists

The task is taken from LeetCode Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: ...
1
vote
0answers
38 views

Prompting the user to input a data value into an element in a linked list

I'm working through a practice problem that is having me build and modify a linked list over a series of steps. I am particularly interested in knowing if there's a more elegant way of prompting the ...
1
vote
0answers
61 views

Hackerrank Beautiful Strings

Problem Statement You are given a string, S , consisting of lowercase English letters. A string is beautiful with respect S to if it can be derived from S by removing exactly 2 characters. ...
1
vote
0answers
62 views

Rotate a list by k elements

The task: Write a function that rotates a list by k elements. For example, [1, 2, 3, 4, 5, 6] rotated by two becomes [3, 4, 5, 6, 1, 2]. Try solving this without creating a copy of the list. ...
1
vote
0answers
53 views

Find the square root of n

The task: Given a real number n, find the square root of n. For example, given n = 9, return 3. My solution: ...
1
vote
0answers
38 views

(Codewars) Linked Lists - Insert Sort

Kata: https://www.codewars.com/kata/linked-lists-insert-sort/train/python Description Write an InsertSort() function which rearranges nodes in a linked list so they are sorted in increasing ...
1
vote
0answers
89 views

Consumer Producer problem solution using JDBI, MySQL, HikariCP

The app suppose to solve a subset of Producer–consumer problem. One producer, one consumer thread and buffer. The idea of the app to handle correctly database downtimes. The solution is to keep ...
1
vote
0answers
41 views

Choose numbers from a grid, minimising the sum

Given a 2-D input matrix, I need to pick elements from it. constraint: you can pick one number at each row, each column given: number boards are given expected output: print least sum of ...
1
vote
0answers
48 views

Finding minimum of a function dependent on a constant number

Question- My approach I noticed that the minimum of a row is when t=k-one of the numbers of that row. Suppose in the above sample case, t=4 which is 6-2. Since we have to find the minimum maximum ...
1
vote
0answers
64 views

I have written two versions of Word Break exhaustive combinations. Please comment

I am solving Word Break II from leetcode. https://leetcode.com/problems/word-break-ii/description/ Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add ...
1
vote
0answers
114 views

Quora upvotes trends Hackerrank challenge

The following code is my solution to an old problem I found today. Input Format Line 1: Two integers, N (1 ≤ N ≤ 106) and window size K (1 ≤ K ≤ N) Line 2: N positive integers of upvote ...
1
vote
0answers
86 views

System on Chip Validator

With reference to my source files, published in the git repository soc-testing I did my best effort at coding, based on 30 years of experience, so I would like to know what I did wrong with my ...
1
vote
0answers
69 views

Python: is answer grader program secure?

I am creating my own problems that people have to solve and I want to make a grader check if a user put in the right answers and then reward them with a flag. My code for one particular problem: <...
1
vote
0answers
471 views

binary search tree Inorder successor to test candidate confidence

Problem statement Given the root node and a node in the binary search tree, find the inorder successor of the given node. Here is the example of binary search tree, Given the node with ...