Interview problem doubt — 2

Revision en2, by getitright, 2017-09-02 23:39:45

Hi codeforces community,

I have been preparing for interview round for placements. I came across these 2 problems which I have not been able to solve for the past 2 days.

Q1) A and B play a game. They are given an array of positive numbers. Each player in his turn picks up 2 numbers from the array such that the difference of the numbers does not exist in the array. He then places the difference into the array too thus increase the array count by 1. Then the next player repeats the same process. The game continues till there are no 2 numbers such that difference does not exist in the array. The one who’s not able to choose numbers loses. If A starts the game and the game proceeds optimally, find who’ll win the game

Example : Input array : 2,5,3

A: 2,5,3,1

B: 2,5,3,1,4

A has no choice so B wins.

Q2) Given a string containing only lowercase alphabets, you have to convert it into a string such that it contains only vowels by doing minimum number of operations. In one operation, you could select a substring always starting from index 0, and move that substring forward or backward. Example of rolling forward or backward are given :

Rolling Forward

Input- axzf

Let index chosen be 0 to 3 and moving it forward

Output- byag

Rolling Backward

Input – axze

Let index chosen be 0 to 2 and moving it backwards

Output- zwyd

Please help me in solving the above problems. I would be highly thankful to you all.

Tags #problem, doubts, #interview

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English getitright 2017-09-04 05:55:19 62
en2 English getitright 2017-09-02 23:39:45 22
en1 English getitright 2017-09-02 23:38:27 1470 Initial revision (published)