How to resolve the algorithm Equilibrium index step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Equilibrium index step by step in the J programming language
Table of Contents
Problem Statement
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices.
For example, in a sequence
A
{\displaystyle A}
: 3 is an equilibrium index, because: 6 is also an equilibrium index, because: (sum of zero elements is zero) 7 is not an equilibrium index, because it is not a valid index of sequence
A
{\displaystyle A}
.
Write a function that, given a sequence, returns its equilibrium indices (if any). Assume that the sequence may be very long.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Equilibrium index step by step in the J programming language
Source code in the j programming language
equilidx=: +/\ I.@:= +/\.
equilidx _7 1 5 2 _4 3 0
3 6
You may also check:How to resolve the algorithm Rosetta Code/Fix code tags step by step in the F# programming language
You may also check:How to resolve the algorithm Boolean values step by step in the SenseTalk programming language
You may also check:How to resolve the algorithm Collections step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Collections step by step in the Objective-C programming language