Runtime errors occur when a program does not contain any syntax errors but asks the computer to…
Flatten Array: Flattening an array means taking an array that may contain nested arrays…