Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
6 votes
1 answer
63 views

Chessboard configuartions with no possible capture on the next move

THE TASK: Given an NxM "chess"board and Q,R,B,K where Q is the number of queens, R the number of rooks, B the number of bishops, and K the number of knights find out how many possible ...
Wow1345's user avatar
  • 121
0 votes
1 answer
107 views

Printing Permutations

Following is a leetcode problem: Given an array nums of distinct integers, return all the possible permutations. You can return all the possible permutations. You can return the answer in any order. ...
Strange Alchemist's user avatar
0 votes
1 answer
148 views

Can I optimize my implementation of generating Fibonacci series using recursion?

My function accepts a number, which generates total Fibonacci numbers. I am using recursion. Please follow the code below, ...
Rahul Shivsharan's user avatar
7 votes
3 answers
2k views

Finding the majority element in an array

A list is said to have a “majority element” if more than half of its entries are identical. In this classical problem the goal consists of determining whether a list a of length n has a majority ...
Soner from The Ottoman Empire's user avatar
5 votes
3 answers
1k views

Separating the even and odd numbers in an array in C

I wrote a working program in C that takes an array with size 2ⁿ, and separates all the even numbers from the odd numbers. For example: Input: {1,2,3,4,5,6,7,8}, Output: {8,2,6,4,5,3,7,1} I want my ...
Coder48's user avatar
  • 171
0 votes
1 answer
94 views

extents_to_array and array_to_extents functions for Boost.MultiArray in C++

This is a follow-up question for A get_extents helper function for Boost.MultiArray in C++. In order to retrieve, manipulate and calculate size information in each dimension from Boost.MultiArray in ...
JimmyHu's user avatar
  • 7,014
1 vote
1 answer
188 views

Recursion with char[] in c#

I am trying to learn recursion and have a question involving an array that needs to be reversed. I am focusing on c# but the language probably doesn't matter a whole lot because my function is not ...
stupidQuestions's user avatar
2 votes
1 answer
559 views

Speeding up a recursive Cantor pairing function

The Cantor Pairing function is a mathematical function which takes two integers and combines them into a single integer that is unique to that pair. This single integer can later be "unpaired" back ...
HomeworkHopper's user avatar
2 votes
2 answers
177 views

Recursive Transversal (Python)

For a programming challenge I was doing, I needed to traverse a list of lists, and while writing the standard 2D traversal function, I thought why not generalise it, so I did. Here's my best effort: ...
Tobi Alafin's user avatar
  • 1,792
4 votes
2 answers
452 views

Replace array element with multiplication of neighbors in Scala

Given an array of integers, update the index with multiplication of previous and next integers, Input: 2 , 3, 4, 5, 6 Output: 2*3, 2*4, 3*5, 4*6, 5*6 Following ...
vikrant's user avatar
  • 405
1 vote
1 answer
93 views

Wrapping certain elements in an array with an array with PHP

I have a function that's doing this correctly, but I feel as though this can be done (possibly) with minimal code, with recursion, but I'm just wracking my brain. Basically I have JSON that gets ...
Aaron Olin's user avatar
3 votes
1 answer
672 views

Checking whether given array is sorted by divide-and-conquer

I've written a code that I try to use divide and conquer approach to determine if the given array is sorted. I wonder whether I apply the approach accurately. ...
Soner from The Ottoman Empire's user avatar
1 vote
1 answer
904 views

Recursive trim() function to handle arrays and objects

I have come up with a recursive function which applies trim() recursively to all string members of an array/object. I don't have any specific quandaries about my ...
MonkeyZeus's user avatar
1 vote
1 answer
103 views

Check if list contains a pair which adds up to a given sum

Kindly review this scala code for given problem and suggest improvements. Problem - Given an array of integers and a target sum, check if array contains a pair which adds up to sum. Example - <...
vikrant's user avatar
  • 405
1 vote
1 answer
500 views

Counting contiguous subarrays with a negative sum

I'm doing a coding challenge that asks to count the number of contiguous subarrays that have a negative sum: A subarray of an n-element array is an array composed from a contiguous block of the ...
Richard's user avatar
  • 171

15 30 50 per page