Giter Site home page Giter Site logo

kata's Introduction

##  Question 1

There is a string S that consists only  of non zero digits (1-9). We can choose two adjacents digits in S and replace them with their sum  but only if the sum is not greater than 9 . For example  if S = "356" we can replace" 35 "with" 8 " achieving " 86 " but we cannot replace 56 with 11. the operation may be applied multiple times in order to produce a final answer.
what is the lexicographically largest string we can obtain ?
A string made of digits is lexicographically larger than some other string if it has larger digit at the first position on which they differ. For exampke string "123" is lexicographically larger than "1134" as at the first position they differ, the first string has digit "2" and the second string has digit "1"
Write a function that given a string S returns lexicographically largest string we can obtain from S.
Examples:
Assuming S= "32581" it is optimal to replace "32" with "5" and "81" with "9". The function should return "559".
Assuming S= "1119812" it is optimal to replace "11" with "2" obtaining 219812. replace "21" with 3 and 81 with 9. the function should return "3992".

## Question 2

We call an array switching if all numbers in even positions are equal and all numbers in odd positions are equal
For example :[3,-7,3,-7,3] and [4,4,4] are switching but [5,5,4,5,4] and [-3,2,3] are not switching.
What is the length of the longest-switching slice (continous fragment ) in a given array A?
Write a function :
Given an array A consisting of N integers, returns the length of the longest switching slice in A. 
Examples 
Given A=[3,2,3,2,3] the function should return 5 because the whole array is switching 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.