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
6
votes
0answers
302 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 ...
6
votes
1answer
222 views

Count the number of inversions using Binary Indexed Tree in an array

Original Problem: HackerRank I am trying to count the number of inversions using Binary Indexed Tree in an array. I've tried to optimise my code as much as I can. However, I still got TLE for the ...
5
votes
0answers
53 views

SQLite In-memory Database That Inserts Data Read From a CSV File

I wrote this program to make a simple in-memory database using SQLite and JDBC. Requirements I was trying to accomplish are below. It should consume a CSV file, parse the data, and insert it into the ...
5
votes
0answers
445 views

Codewars: N-dimensional Von Neumann Neighborhood in a matrix

Task: For creating this challenge on Codewars I need a very performant function that calculates Von Neumann Neighborhood in a N-dimensional array. This function will be called about 2000 times The ...
5
votes
0answers
88 views

Avoiding direct recursion with Composite/Visitor patterns?

This year's AoC has a puzzle for day 24 that was (supposedly) intended to be solved with recursion. Here is description: I've solved it via simple direct recursion: ...
5
votes
1answer
542 views

HackerRank ACM ICPC Team

You are given a list of \$N\$ people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-person team can ...
4
votes
0answers
58 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 ...
4
votes
0answers
87 views

Merge Intervals in JavaScript

This task is taken from Leetcode - Given a collection of intervals, merge all overlapping intervals. Example 1: ...
4
votes
0answers
90 views

Implement a readN() from read7()

Exercise: Using a read7() method that returns 7 characters from a file, implement readN(n) which reads n characters. ...
4
votes
2answers
113 views

Heights of Cats

I have an assignment to solve this problem. However, I have exceeded the time limit required, can anyone suggest where to improve my code? Cats like to sit in high places. It is not uncommon to see ...
4
votes
0answers
546 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, ...
4
votes
1answer
67 views

Sorting software version list using Python 2.7 (no modules)

I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution: ...
4
votes
0answers
42 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 ...
4
votes
0answers
257 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. ...
4
votes
0answers
205 views

Time Limit Exceeded with shortest path algorithm

The problem: SHPATH You are given a list of cities. Each direct connection between two cities has its transportation cost (an integer bigger than 0). The goal is to find the paths of ...
4
votes
0answers
109 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 ...
3
votes
0answers
35 views

(Leetcode) Snakes and Ladders

This is a Leetcode problem - On an \$N\$ x \$N\$ board, the numbers from 1 to N * N are ...
3
votes
0answers
33 views

Find the starting indices of all occurrences of the pattern in the string - KMP algorithm follow-up

The task was initially solved here, but was too buggy: Given a string and a pattern, find the starting indices of all occurrences of the pattern in the string. For example, given the string "...
3
votes
0answers
77 views

LeetCode: Add and Search Word - Data structure design

This is a Leetcode problem: Design a data structure that supports the following two operations: void addWord(word) ...
3
votes
0answers
31 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 ...
3
votes
0answers
83 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 ...
3
votes
1answer
85 views

Find out how many laptops Molly can buy based on available money, array of quantities and array of costs

Problem description: Molly wants to purchase laptops for her school. Find out how many laptops she can purchase by comparing the vendors available. Each vendor sells the laptops in batches, with ...
3
votes
1answer
79 views

React.js Nested Nav Bar

This was written for a coding challenge for a company I recently starting working for. I'm looking for any suggestions on how to clean up the code, as well as any issues anyone thinks may occur as it ...
3
votes
0answers
72 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 ...
3
votes
0answers
228 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 ...
3
votes
1answer
73 views

Leetcode Mountain Array

I've been working on longest mountain in array on Leetcode: Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: ...
3
votes
1answer
102 views

Search and Replace (FreeCodeCamp intermediate algorithm scripting)

I completed the challenge and passed the tests: Perform a search and replace on the sentence using the arguments provided and return the new sentence. First argument is the sentence to perform ...
3
votes
2answers
209 views

Find the sum of all digits that match the following digit in a circular list

The challenge The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit ...
3
votes
0answers
94 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 ...
3
votes
0answers
75 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, ...
3
votes
0answers
107 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). ...
3
votes
0answers
323 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 ...
3
votes
0answers
121 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 ...
3
votes
0answers
898 views

Hackerrank: Sherlock and anagram

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 ...
3
votes
0answers
485 views

Hackerearth Simple Function - Follow-up

Problem statement Let us first describe a SimpleFunction: ...
3
votes
0answers
883 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 ...
3
votes
0answers
318 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 ...
3
votes
0answers
137 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 ...
3
votes
0answers
64 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, ...
3
votes
0answers
86 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 ...
2
votes
1answer
68 views

Find A Series of Numbers Who when Squared and Summed are equal to a given Square

I am working on a CodeWars titled 'Square into Squares. Protect trees!' it can be found here: https://www.codewars.com/kata/54eb33e5bc1a25440d000891/train/javascript I have a working solution, the ...
2
votes
0answers
33 views

LeetCode: Remove Duplicates from Sorted Array

Please review for performance https://leetcode.com/explore/featured/card/top-interview-questions-easy/92/array/727/ Given a sorted array nums, remove the duplicates in-place such that each ...
2
votes
0answers
81 views

(Leetcode) Longest consecutive sequence in Python

This is a Leetcode problem - Given an unsorted array of integers, find the length of the longest consecutive elements' sequence. Your algorithm should run in \$O(n)\$ complexity. ...
2
votes
0answers
61 views

Bursting Balloons

This is a Leetcode problem - Given n balloons, indexed from 0 to n-1. Each balloon is ...
2
votes
0answers
52 views

Frog Jump time complexity

I have tried to work out the Frog Jump task on Codility. The algorithm for solving this is rather simple but the maximum score I am able to achieve is 55% (also 44% with modulus operations). A ...
2
votes
0answers
67 views

Coding Challenge Solution - Find Number of Elements in a range in \$O(1)\$ with preprocessing

Overview This is my solution to the following Coding Challenge - Find Num of Elements in a Range in \$O(1)\$ with Preprocessing - Given an array and max element in the array, find the number of ...
2
votes
0answers
85 views

Daily coding problem 18: Maximums of k-sized windows

The challenge Given an array of integers and a number k, where 1 <= k <= length of the array, compute the maximum values of each subarray of length k. For example, given array = [10, 5, 2, 7, ...
2
votes
0answers
72 views

Determine whether there exists a one-to-one character mapping from one string to another

The task Determine whether there exists a one-to-one character mapping from one string s1 to another s2. For example, given s1 = abc and s2 = bcd, return true since we can map a to b, b to ...
2
votes
0answers
49 views

Code Chef's Cleaning Tables: find the minimum number of tables to clean

Description: Haku has been newly hired by Chef to clean tables at his restaurant. So whenever a customer wants a table, Haku must clean it. But Haku happens to be a lazy boy. So in the ...
2
votes
0answers
620 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 ...