File tree Expand file tree Collapse file tree 3 files changed +129
-0
lines changed
algorithm-exercises-csharp/src/hackerrank/warmup
algorithm-exercises-csharp-test/src/hackerrank/warmup Expand file tree Collapse file tree 3 files changed +129
-0
lines changed Original file line number Diff line number Diff line change
1
+ namespace algorithm_exercises_csharp . hackerrank ;
2
+
3
+ [ TestClass ]
4
+ public class StaircaseTest
5
+ {
6
+ [ TestMethod ]
7
+ public void testStaircase ( )
8
+ {
9
+ int input = 6 ;
10
+ string expectedAnswer = String . Join ( "\n " ,
11
+ " #" ,
12
+ " ##" ,
13
+ " ###" ,
14
+ " ####" ,
15
+ " #####" ,
16
+ "######"
17
+ ) ;
18
+
19
+ string result = Staircase . staircase ( input ) ;
20
+
21
+ Assert . AreEqual ( expectedAnswer , result ) ;
22
+ }
23
+ }
24
+
Original file line number Diff line number Diff line change
1
+ // @link Problem definition [[docs/hackerrank/warmup/staircase.md]]
2
+
3
+ namespace algorithm_exercises_csharp . hackerrank ;
4
+
5
+ using System . Text ;
6
+ using System . Diagnostics . CodeAnalysis ;
7
+
8
+ public class Staircase
9
+ {
10
+ [ ExcludeFromCodeCoverage ]
11
+ protected Staircase ( ) { }
12
+
13
+ public static string staircase ( int _n )
14
+ {
15
+ List < string > result = [ ] ;
16
+
17
+ for ( int i = 1 ; i < _n + 1 ; i ++ )
18
+ {
19
+ StringBuilder line = new ( ) ;
20
+
21
+ for ( int j = 1 ; j < _n + 1 ; j ++ )
22
+ {
23
+ if ( j <= _n - i )
24
+ {
25
+ line . Append ( ' ' ) ;
26
+ }
27
+ else
28
+ {
29
+ line . Append ( '#' ) ;
30
+ }
31
+ }
32
+
33
+ result . Add ( line . ToString ( ) ) ;
34
+ }
35
+ return String . Join ( "\n " , result ) ;
36
+ }
37
+
38
+ }
Original file line number Diff line number Diff line change
1
+ # [ Staircase] ( https://www.hackerrank.com/challenges/staircase )
2
+
3
+ Difficulty: #easy
4
+ Category: #warmup
5
+
6
+ Staircase detail
7
+ This is a staircase of size $ n = 4 $:
8
+
9
+ ``` text
10
+ #
11
+ ##
12
+ ###
13
+ ####
14
+ ```
15
+
16
+ Its base and height are both equal to n. It is drawn using # symbols
17
+ and spaces. The last line is not preceded by any spaces.
18
+
19
+ Write a program that prints a staircase of size n.
20
+
21
+ ## Function Description
22
+
23
+ Complete the staircase function in the editor below.
24
+
25
+ staircase has the following parameter(s):
26
+
27
+ * int n: an integer
28
+
29
+ ## Print
30
+
31
+ Print a staircase as described above.
32
+
33
+ ## Input Format
34
+
35
+ A single integer, , denoting the size of the staircase.
36
+
37
+ Constraints
38
+
39
+ $ 0 < n \leq 100 $
40
+
41
+ ## Output Format
42
+
43
+ Print a staircase of size n using # symbols and spaces.
44
+
45
+ Note: The last line must have spaces in it.
46
+
47
+ ## Sample Input
48
+
49
+ ``` text
50
+ 6
51
+ ```
52
+
53
+ ## Sample Output
54
+
55
+ ``` text
56
+ #
57
+ ##
58
+ ###
59
+ ####
60
+ #####
61
+ ######
62
+ ```
63
+
64
+ ## Explanation
65
+
66
+ The staircase is right-aligned, composed of # symbols and spaces,
67
+ and has a height and width of $ n = 6 $.
You can’t perform that action at this time.
0 commit comments