Commonly asked Recursion Interview Question - Print an interesting Pattern using Recursion -

preview_player
Показать описание
Commonly asked Recursion Interview Question - Print a Pattern using Recursion

Problem Statement :
Print a pattern using recursion : 16 11 6 1 -4 1 6 11 16

In this video we will print a very interesting pattern using recursion. You will see how to approach question of recursion and write the code.

PrepBytes is India's only personalised mentorship driven courses and programs platform. Our motive is that everyone should code and everyone should achieve their dream job.
Рекомендации по теме
Комментарии
Автор

The only problem in this question is decrease n till it is greater than zero and make this a base condition and print then dig inside it as n-5; outside the base condition print and backtrack....🙂✌️

biswamohandwari
Автор

I know ur good with ur professonal but here we are student so student samjh k padhao, ppt presentation k hisab se nhi smjhana hai batana nhi hai ek prorgramme peoperly banao batao kaise kya work krta hai, bss working he bataya nad bich bich me baki chize thod student k dmg se bataye mam.byw nice video.

ronnygamerz
Автор

I solved this problem without using recursion, it is giving the output as required, but still showing wrong answer after submission, why is it so??? @prepbytes please reply

ujjwaldeep
Автор

Why don't you try to zoom out your text, if there is no space then try saperate tab. You guys make it more complicated than it actually is

amandarash
Автор

// my take on the solution
var n int
func main() {
n = 1
r(n, false)
}
func r(val int, isPassedMidpoint bool) int {
log.Print(val)

if val+5 > n && isPassedMidpoint {
return val
}
if val > 0 && !isPassedMidpoint {
return r(val-5, isPassedMidpoint)
} else {
isPassedMidpoint = true
return r(val+5, isPassedMidpoint)
}
}

kellyfreet
welcome to shbcf.ru