Stack Exchange Network

Stack Exchange network consists of 175 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.

2
votes
1answer
22 views

Project Euler #5 in C++

I'm currently doing the Project Euler challenges to learn C++. The fifth problem is the following. 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any ...
1
vote
0answers
32 views

Find non-duplicated integer in a list where every integer occurs three times except for one integer

The task Given an array of integers where every integer occurs three times except for one integer, which only occurs once, find and return the non-duplicated integer. For example, given [6,...
3
votes
1answer
65 views

Division without using division, multiplication, or modulus operators

The task Implement division of two positive integers without using the division, multiplication, or modulus operators. Return the quotient as an integer, ignoring the remainder. My solution <...
0
votes
1answer
22 views

Time limit exceeded in K-th symbol in Grammar (LeetCode)

I am taking efforts to solve problem K-th Symbol in Grammar - LeetCode K-th Symbol in Grammar On the first row, we write a 0. Now in every subsequent ...
17
votes
3answers
3k views

Project Euler #1 in C++

I'm learning C++ and currently doing Project Euler challenges. The first challenge is the following. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. ...
5
votes
1answer
167 views

Finding the upper and lower bound using binary search

I am trying to solve this InterviewBit question https://www.interviewbit.com/problems/search-for-a-range/. My code for this seems to be working properly and it does give me the correct answers on my ...
1
vote
2answers
42 views

Sum of two numbers in array

The task You are given two non-empty arrays representing two non-negative integers. The digits are stored in reverse order and each of their items contain a single digit. Add the two numbers ...
1
vote
1answer
40 views

Find busiest period in building

The task You are given a list of data entries that represent entries and exits of groups of people into a building. An entry looks like this: {"timestamp": 1526579928, count: 3, "type": "...
0
votes
1answer
36 views

Making Anagram Problem Implementation

Problem Statement Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged ...
1
vote
1answer
47 views

MinMax Problem Implementation

Problem Statement: You will be given a list of integers, arr, and a single integer k. You must create an array of length k from elements of arr such that its unfairness is minimized. Call ...
0
votes
1answer
40 views

Find indices of two numbers such that they add up to a target

The task ...is taken from leetcode Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ...
3
votes
1answer
56 views

Given a list of coordinates, find the rectangle with minimal area

A problem on leetcode asks the coder to write an algorithm to take a bunch of coordinates in the xy-plane and return the minimum area of a rectangle made from four of these coordinates (or return <...
2
votes
0answers
38 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 ...
1
vote
0answers
37 views

Find all pairs of unique indices in a list such that the concatenation of the two words is a palindrome

The task Given a list of words, find all pairs of unique indices such that the concatenation of the two words is a palindrome. For example, given the list ["code", "edoc", "da", "d"], return ...
0
votes
0answers
49 views

Codility Ladder (Fibonacci) lesson [on hold]

I am trying to solve the "Ladder" problem from Codility. I got only 37% score (75% for correctness and 0% for performance). Can anyone help to identify the problem in my code. I found an optimal ...
1
vote
1answer
44 views

Rotate a N by N matrix by 90 degrees clockwise

The task: Given an N by N matrix, rotate it by 90 degrees clockwise. For example, given the following matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] you should return: [[7, 4, 1], [8, ...
1
vote
1answer
61 views

Given a list and a number k return whether any two numbers from the list add up to k

The task: Given a list of numbers and a number k, return whether any two numbers from the list add up to k. For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. ...
1
vote
1answer
41 views

Check whether string of brackets are well-formed

The task I asked similar questions here and here. Given a string of round, curly, and square open and closing brackets, return whether the brackets are balanced (well-formed). For example, ...
3
votes
3answers
56 views

Implement integer exponentiation faster than repeated multiplication

The task: Implement integer exponentiation. That is, implement the pow(x, y) function, where x and y are integers and returns x^y. Do this faster than the naive method of repeated ...
2
votes
0answers
30 views

Polymorphic DBConnector class exercise

GitHub GItHub if it's easier I'm in the process of doing a training course in C#. I've just gone over covering Polymorphic OOP / composition over inheritance etc... The latest exercise I completed ...
7
votes
3answers
1k views

One-dimensional Japanese puzzle

I have been practicing competitive coding for a while now and am using codeforces.com. I recently encountered a problem called "One Dimensional Japanese Crossword" on that site. The problem is as ...
3
votes
1answer
55 views

Google Kick Start Practice Round 2019 - Mural

My code exceeds the time limit on the second test set. A suggestion/hint of a better algorithm would be appreciated. Problem Thanh wants to paint a wonderful mural on a wall that is N ...
2
votes
1answer
80 views

Stopwatch exercise from training course

Github Github for easy testing I'm currently undertaking a training course to try & further develop my skills in C#. The latest exercise was to create a basic stopwatch class that meets the ...
4
votes
2answers
74 views

Check whether string of braces, brackets, and parentheses is balanced

The Task is taken from codewars: Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return true if ...
1
vote
2answers
98 views

Leetcode: Roman digit to integer

I tried to solve the question at https://leetcode.com/problems/roman-to-integer/ i.e Converting an Roman Digit to a Integer using C#. It passes all the test cases but any suggestions to reduce run ...
1
vote
0answers
76 views

HackerRank Equal Solution [closed]

Source: https://www.hackerrank.com/challenges/equal/problem Problem Description: Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. She is ...
1
vote
2answers
62 views

Minimum number of parentheses to be removed to make a string of parentheses balanced

The task: Given a string of parentheses, write a function to compute the minimum number of parentheses to be removed to make the string valid (i.e. each open parenthesis is eventually closed). ...
1
vote
1answer
44 views

Return a new array where each element is the number of smaller elements to the right of that element in the original input

The task: Given an array of integers, return a new array where each element in the new array is the number of smaller elements to the right of that element in the original input array. For ...
6
votes
2answers
75 views

Find duplicate in linear time and space

The task: You are given an array of length n + 1 whose elements belong to the set {1, 2, ..., n}. By the pigeonhole principle, there must be a duplicate. Find it in linear time and space. <...
4
votes
1answer
33 views

Code to find if a number fulfills certain requirements (e.g. sequential increasing, palindrome, repeating, etc)

I'm currently a 3rd year computer science student and lecturers have never checked the readability and maintainability of code. We were only marked on our outputs and as such I've written some truly ...
1
vote
0answers
30 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. ...
2
votes
0answers
58 views

Return whether a string is a palindrome if you can delete at most k elements

The task: Given a string which we can delete at most k, return whether you can make a palindrome. For example, given 'waterrfetawx' and a k of 2, you could delete f and x to get '...
1
vote
0answers
52 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. ...
2
votes
1answer
39 views

Leetcode: Detecting duplicate elements in an array within a k-element window

Upon solving the problem 'contain duplicates` in leetcode: Given an array of integers and an integer k , find out whether there are two distinct indices i and j in the array such that nums[i] = ...
1
vote
0answers
56 views

Sort a list using a reverse helper function

The task: Given a list, sort it using this method: reverse(lst, i, j), which reverses lst from ...
1
vote
1answer
41 views

Programming Challenge from Kattis: Distinctive Characters

I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. ...
1
vote
2answers
55 views

Find the smallest distance between any two given words in a string

The task: Find an efficient algorithm to find the smallest distance (measured in number of words) between any two given words in a string. For example, given words "hello", and "world" and a ...
1
vote
1answer
59 views

Leetcode online Find the judge, graph with highest degree

Here is the problem. In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town ...
0
votes
0answers
40 views

Kadane's algorithms to leetcode “121 Best Time to Buy and Sell Stock”

I employed the conventional Kadane's algorithms to solve a maximum subarray problem in leetcode Best Time to Buy and Sell Stock - LeetCode Best Time to Buy and Sell Stock Say you have ...
3
votes
1answer
54 views

4 solutions to leetcode 202. Happy Number have almost same performance

I am working on an easy math question Happy number Happy Number - LeetCode Happy Number Write an algorithm to determine if a number is "happy". A happy number is a number defined by ...
1
vote
1answer
32 views

Exceeded time limit to solve super pow

I tried to solve the Super Pow - LeetCode Super Pow Medium Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in ...
3
votes
0answers
22 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 ...
5
votes
1answer
98 views

Return the first recurring character in a string

The task: Given a string, return the first recurring character in it, or null if there is no recurring character. For example, given the string "acbbac", return "b". Given the string "...
4
votes
1answer
71 views

Determine whether any permutation of a string is a palindrome

The task: Given a string, determine whether any permutation of it is a palindrome. For example, "carrace" should return true, since it can be rearranged ...
2
votes
1answer
37 views

Kahn's algorithms to arrange CouseSchedule

I wrote a solution to Course Schedule II - LeetCode There are a total of n courses you have to take, labeled from 0 to n-1. ...
2
votes
1answer
34 views

Kattis Problem 'Mali'

I wrote a solution to the Mali problem on Kattis: Given inputs a1, a2, a3, …, an and b1, b2, b3, …, bn, determine n pairings (ai, bj) such that each number in the A sequence is used in exactly one ...
10
votes
3answers
1k views

Find the majority element, which appears more than half the time

The task: Given a list of elements, find the majority element, which appears more than half the time (> floor(len(lst) / 2.0)). You can assume that such element exists. For example, ...
3
votes
1answer
78 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 ...
5
votes
2answers
109 views

Programming Challenge from Kattis: Watchdog

I've tried to solve the kattis-challenge called Watchdog. My code works just fine, but it was too slow on the last test. I'm wondering if anyone sees any big algorithmic performance issues. A short ...