Trilogy OA Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

0 Codewriting

DESC
maln.cpp
You're creating a new 1 int solution
programming language with
some exciting new featurest Any
2

programming 3 )
language cacheck if two strings are 4
HISTORY
you'd like yours to be able to check if
matching, but
they're almost
matching More specifically, we'lil say two strings are
RULES
almost matching if they're equal in length and of
all
their corresponding characters are the
same except
for one. For example, "cat" and
"bat" are
README almost matching, but "cat" and "dog are not
For the sake of efficiency,
youre planning on testing
he feature by using a single
string andcomparing its
SETTINGs substrings, Givena string s and an integer k
your task is to find the number of pairs of
of
substrings
that are almost matching but differ at
their
Kh character (0-based), it's
necessary that the
length of both sutbstrings exceeds k
(otherwise the
strings wouldn't have a kh character),
Also note that substrings are
determined by their
indices, so there could potentially be
multiple
instances of the same word. For example, in the
word " ingratiating" the substring
ing" TESTS
IMOR CUSTOM TESTS
app.codesignal.com/test/waxzikpWkhiWXtBb/question/K36bi4EgomKn
ACK TO GUESTIONS

=3
<
maln.cppP
sC .("ab" , "ac" )- i =4, j - 5, 1= 2. n
1 int solution (s t
3
3}
STORY Input/Output
" [execution time limit] 0.5 seconds (cpp)
RULES
"(memory limit) 1GB
" (input) string s
README
Astring consisting only of lowercase Engiish
letters.

SETTINGS
Guaranteed constraints
1ss.length s 200

" [input) integer k

Guaranteed constraints:
0sk <s.length

- [output] integer

The amount of different pairs as described


above.
TESTS CUSTOHTESTS
1 MORE
HACK TO QUESTIONS

Codewriting main.cpp
SC 1 vector<int> sc
Problem Description 2
3 }
Welcome to the magical world of Mario's adventure 4
rORY
where Mario is standing on platform 0 and needs to
reach platform A+1. But oh no, there's a wide river
that's A units wide blocking his way. Mario can't
ULES
walk
on water, but he's got an amazing
ability - he can
jump up to B units at a time, either forward or
backward.
EADME I
On the river, there are
various-sized wooden
platforms floating on the river just like in Mario's
SETTINGs games. In total there are M platforms and their sizes
are stored in an integer array C. Mario can
move
these platforms around, but he can't change their
order or let them overlap. Note that he should first
move the platforms and then start his journey. Help
Mario cross the river and reach platform A+1.

If it is impossible to reach A+1, your answer will be a


vector containing-1, acknowiedging the challenge.
Yet, if a solution exists, return a vector of size A
representing the sequence of river cells. If cellidoes
TESTS CUSTONTENIR
MORE
Example Output main.cpp
1 vector<
Output1 : 2

[0, 1,0, 2, 2, 0, 3] 4
3}
RY
Output2:

[0, 0, 0, 0, 1, 1, 0, 0, 0, 0]
ES

Example Explanation
ADME
For Input 1:

The lexicographically smallest possible answer is [0,


1,0, 2, 2, 0, 3].
ETTINGs
The sequence of jumps Mario performs is 0 2 4
-578.

For Input2:

The lexicographically smallest possitble


answer is [0,
0,0, 0, 1, 1,0, 0, 0, 0].
The sequence of jumps you perform is 0 5 6
11

[execution time limit] 0.5 seconds (cpp)


TESTS
MORE
<
Input/Output main.cpp
1 ec
2
" [execution time limit] 0.5 seconds (cpp)
RY " [memory limit] 1 GB
" [input] array.array.char field
ES Anon-enmpty
rectangular matrix of characters
representing a field.

ADME Guaranteed constraints:


1s field. length s 12
1s field [0].1ength s 12
ETTINGS
"[output] array.integer
Array of two elements, where the first element
is the
minimum number of moves and the
second one in the maximum number of
moves
required to fill the first column. It is
that the maximum quaranteed
number of moves doesn't
exceed 12.

(C+1 Syntax Tips

HORE TESTS
app.codesignal.com/test/ w9ak21 VKnIVWAt On/wikk4tA/SZKKm

BACK TO QUESTIONS

Example < main.cpp


ESC
1 int solution (
2
" For crypt =["SEND", "MORE", "MONEY"],
the output should be
3}
solution (crypt) =1,because there is
ISTORY
only one solution to this cryptarithm:
0 =0,M=1, Y =2, E = 5, N=6, D
RULES
=7, R =8,and s =9(9567 + 1085 =
10652 ).
" For crypt = ["GREEN", "BLUE", "BLACK"]
README
the output should be
solution (crypt) = 12, because there are
12 possible valid solutions:
o 54889 + 6138 61027
SETTINGS
18559 + 2075 20634
72449 + 8064 = 80513
48229+ 5372= 53601
47119 5261 52380
36887+ 4028 40915

83447 + 9204 - 92651


74665 8236 = 82901

65884 4 7308 73192


57883 6408 64291
578816428 64309
TESTS CUSTOH TESTE
1MORE
5apcodesignal com test/wa2RWKhWXE3b/question/wikk4EXi
DUESTONS

57883 64086429l maln.cpp


S7881 6428 64309 1 nt solut
83441 4 9264 92705
-Fr cypt ONE, THO. THREE"]
the outpt shouid be solution
(crypt)0,
because there are no valid solutions

Input/Output
-jexecution time limit) 0.5 seconds (cpp)
-memory limit) 1GB
-input array.string crypt
Aray of three non-empty strings
anly uppercase Engish letters
containing

Guaranteed constraints
LScypt[l-lengths 35
- outpug integer

The umber ot vald


solutions
CSyntax Tips
TESTS
BACK TO QUESTIONS

Codewriting
SC
main.cpp
Acryptarithm is a 1 int solution
mathematical puzzle where the 2
goal is to find the
correspondence between letters 3}
and digits such that the given 4
TORY arithmetic equation
consisting of letters holds true.
Given a cryptarithm as an array of
strings crypt
ULES
count the number of its valid I
solutions.
The solution is valid if each
letter represents a
EADME different digit, and the leading digit of any
number is not zero. multi-digit
crypt has the following structure:
[wordl,
SETTINGS word2, word3], which stands for the
word1l
word2 = word3
cryptarithm.
Example
" For crypt ["SEND", "MORE",
the output should be
"MONEY"1
solution (crypt) 1, because there is
only one solution to this cryptarithm:
O0,M1, 2E5N6,
Y
D
7R8,and S=9 (95674 108S
1 MORE TESTS CUSTOHTEST
Example main.cpp
ESC 1 ec
. For

STORY field =I . , ' , '#1.


1.
RULES
the output should be
solution (field) [4, 4].
README We need to cho0se the first row once
and the
third row three times.

SETTINGS

For

field [.

the output should be


soluti on (field) [3, 6]
TESTS CUSTOHTE
MORE
BACK TO QUESTIONS

For example, if the board looks like this


main.cpp
DESC 1 vector<ir
2
3
4

AISTORY
blocks are denoted by ' and empty cells are
denoted by
RULES
and you throw a block into the first or
the second row
from the top, it will end up like this:
README

SETTINGS

Your task is to
calculate the minimum and the
maximum number of moves required to fill the first
colurnn of the board with blocks.

Example
" For

FieldI,a,
TESTS
CURTOTEST
O Codewriting
main.cpp
SC
You are given a rectangular board 1 Fectorci
divided into a 2
uniform grid (square cells). Some cells of the board 3 }
are occupied with blocks,
TORY and others are empty. You
are trying to add more and
more blocks to the board,
and your task is to fill the first
column with them.
Your can add a block to the
ULES field in the following way:
first, youchoose the row index, then
you throw the
new block into the
chosen row from the left. The
README
block appears in the leftmost cell of
the row and
starts moving to the right, until it
block or the end of the row. reaches another
When that happens, the
SETTINGS
block starts falling down until in
block or the last row. reaches another
For example, if the board
looks like this

blocks are dencted by ' and empty cells are


denoted by
and you throwNa
block into the first or the
Second row TESTS
CUSTOHTESTS
Input Format
main.cpp
The first argument is an integer A 1 Fectorc
2
The second argument is an integer B 3
The third argument is an integer aray C 4
TORY

Output Format
RULES Return an integer array representing the
answer.
Example Input
README
Input 1:

A=7
SETTINGs B=2
C(1,2, 1]
Input 2 :

A 10
B5
C (21

Example Output
Outputs
TESTS
TO QUESTIONS

[input] string s main.cpp


1 int solution (string
Astringconsisting only of lowercase English 2

letters.
3 }

Guaranteed constraints
1ss.length s 200

ES " [input] integer k

Guaranteed constraints
0sk <s.length
ADME

" [output] integer

TTINGS
The amount of different pairs as described
above.

[C++] Syntax Tips

11 Prints help message to the console


11 Returns a String
string hellowor ld(s tring name) (
cOut cThis prints to the
cosole whe
return "Hello, name:

TESTS CUSTDH TESTR


MORE
23 app.codesignal.com/test/w9aX2iRpWKhiWXt3b/question/K36biX4EgomKmiYTj
CK TO QUESTIONS

instances of the same word. For example, in the < main.cpp


word "ingratiating" the
substring "ing" 1 int solution (string s,
beginning at indexo is considered distinct from the 2

one at index 9 (and there are also two distinct 3}

RY "ati" sbstrings).

Example
ES
For s "abacaba" andk= 1,the output should
be

solution (5, k) 8
ADME
Using i and j to represent the start and end
indices of the first substrings, and 1 and m to
fepresent the indices of the second substring, the 8
TTINGS
pairs are:

("aba" "aca" )- i -0, j - 2. 1 2.


m4

-("aba" "aca" )- i = 4,j- 6, 1-2.


m4

""aca"
"aba" ) - i = 2, j= 4, 1-0,
m21
" ("aca"aba")- i= 2. j - 4, 1-4,
m6

"ac" "ab )-i2, j=3, I-0, TESTS


MORE CUSTON TESTS
YchfjQpkn6N
Maps Byteverse PPT Format

Question 2 of 4 Submitted v

malnJava
1 int [) solution (int a, int b, int[] ) {

int res[]= new int[a];


int m=C.length;
int total=0;
for(int len:c) total+-len;
8 int rem=a-total;
int curr=0;
10 for(int i-0;i<m; i++) {
11 int pos= currMath .min(rem, b-1);
12 rem-=pos- Curr;
13
14 for(int j-0; j<c[i] ;j+){ I
15 res[pos+j]-i+1;
16
17
18 curr=pos+c[i];
19
20 int lastpos-0;
21 for(int i-0;i<a; it+){
if(res[i]l=0){
23 if(i-lastpos>b) {
24 return new int[]{-1};
25
26 lastpos=i+c[res[i]-1] -1;
27
28
29
30
31 if(a-lastpos>b) return new int0{-1):
32 return res;
33
34

TESTS CUSTOM TESTS

ASUS Vivobook

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy