Please help solve the below questions

These are the 2 questions asked in Samsung South Korea Internship test. Please help me solve them.
https://drive.google.com/file/d/1kfwfWaMYkyALRKCPT2FQ8JZA4yBrX2X9/view?usp=sharing

i will try to help

what is not understood to you in this?

Not able to build logic for both

in first question you can use recursion
explore all possibilities
constraints are also less so no problem occur 10<=N<=15

Can you please share ur code for the same as I am not able to code this

Coding Blocks IDE
Please check my code, getting wrong output.

What kind of doubt support is this…it’s been 2 days and still not a single reply for my doubt

Sorry I forgot to reply

You are using loops in this question
Which will not explore all the paths

You have to use recursion here
make two case either place the tile horizontally or vertically
inside each case there are 3 sub cases
if(no_of_ones >=4) place 4X1 tile
if(no_of_ones>=3) place 3X1 tile
if(no_of_ones>=2) place 2X1 tile

use BFS approach

I told you the same thing above that I am not able to code the same. Please share your code so that I get a understanding of the problem.

I have not written code for this
i can convey the logic you have to implement it

So please write the code, I do not know how to apply bfs approach in case of this type of questions.
If I knew how to do the problem I would have sent you the code not the problem itself.

Can u please help me with this??

i am writing the code
i will send you shortly

my Code

i have tried it for 2 testcase both gives correct ans
also check for other

Can u please do 2nd ques also.

I have 2 doubts in this:

  1. why have you written if(x>200) return false;
  2. if(ones_right>=2){ here u have used 4 if conditions inside it} But for all other ones >=2 u have only used 3 if conditions. Why??

this is for testing you can remove it now

Yes there are 3 if else conditions in ones_right
there should be 3 condition in all other as well

Final Modified Code

look at this code
and if you have any doubt in question 1
feel free to ask

and for question-2 please post a new doubt

I have some doubts in ques 1:

  1. u told me that we will use bfs in it but we have simply used recursion here. How is it bfs??
  2. Coding Blocks IDE Here I am trying to print the park_map and it is printing wrong map for 1st test case. Why??
  3. Can we optimise it using dp??
  4. How much time did it take you to solve this? I mean is this question solvable in a test in limited time??
  5. How do you approach such questions?? Have u already done this type of questions that why you solved it easily??

basically both are not much different
in bfs we also make a visited array (in this case i used the same array with marking =2)
in simple recursion we don’t use visited generally
bfs is a graph algorithm which is based on recursion

it is not printing wrong ans
actually i use 2 as visited or not
if a cell is 2 that means we visited that cell

NO
because for dp the 2 condition doesn’t fulfill

first time i write code in 20min
but when i run, it fails. then i identify my mistake

i again write it in 15 mins with some modification
but then some corner cases fails
in correcting those cases and debugging the code it tooks 30mins
because i didn’t write such code in recent times

in interview a person can code it in 30-40 mins (single question)

u told me that we will use bfs in it but we have simply used recursion here. How is it bfs??
But we use a queue and insert elements in bfs but here we haven’t used it??

it is not printing wrong ans
actually i use 2 as visited or not
if a cell is 2 that means we visited that cell
I know this but open the link once, it is printing map with 1’s for test case-1 which is wrong.

in interview a person can code it in 30-40 mins (single question)
Don;t you think it was very tough question?? How do you build logic for such questions??