Walmart | Phone | String and Tree

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-07-17Added By Anonymous
Source: Link

Hi community,

I've been using leetcode for a while, so wanted to return some to community.

I had 1st round walmart interview today.


Question 1) For a given string, we want to count how many palindromic substrings are there. With the exception of strings of length1. Second modification to this question is,

We want to print all the palindromic substrings.


Ex:

ABBA -> 2 (BB, ABBA)

ABCCBA -> 3(CC, BCCB, ABCCBA)

CBBBBC -> 4(BB, BB, BBBB, CBBBBC)

I did gave solutions. But complexity wise they were very bad.

The acceptable solution should be atmost n ^2


Question 2) For a given tree, find out if a sum exists in the tree

2 parts of this problem

i) Check in a way that root is part of the solution.


ex: when sum =

6 :: 1 -> 2 ->3 and 1 ->4 -> 1

1.Each node can be considered root as in
2.When sum is 6
3.1->4->1

4->1(left leaf sub child of 4 not the root)->1


When sum : 11

[1,2,3,4,1]

For this we had to print the path as well.

I was not able to solve the second part of this problem.


Verdict : ""

Comments