Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6dda2b2

Browse files
"Update approach to solve N-th Tribonacci Number and Two Sum problems with additional information and formatting"
This commit includes updates to the approach sections for the N-th Tribonacci Number and Two Sum problems. It adds more
2 parents 868b3e5 + ae9917f commit 6dda2b2

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

‎N-th Tribonacci Number/Approach-to-solve.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The Tribonacci sequence is a generalization of the Fibonacci sequence, where eac
1010
<li>If n is 0 or 1, return n as the result since the sequence starts with 0, 1, 1.</li>
1111
<li>Use a for loop starting from i = 3 to n.</li>
1212
<li>In each iteration, compute the sum of the last three terms (a, b, and c) and update the variables accordingly.</li>
13+
<<<<<<< HEAD
1314
<li>After the loop, the value of c will represent the nth term of the Tribonacci sequence. </li>
1415
<li>Return the value of c as the result.</li>
1516
</ul>
@@ -20,17 +21,38 @@ The Tribonacci sequence is a generalization of the Fibonacci sequence, where eac
2021
return n;
2122
}
2223

24+
=======
25+
<li>After the loop, the value of c will represent the nth term of the Tribonacci sequence. +</li>
26+
<li>Return the value of c as the result.</li>
27+
</ul>
28+
29+
30+
int a = 0, b = 1, c = 1;
31+
32+
if (n == 0 || n == 1) {
33+
return n;
34+
}
35+
36+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
2337
for (int i = 3; i <= n; i++) {
2438
int sum = a + b + c;
2539
a = b;
2640
b = c;
2741
c = sum;
2842
}
43+
<<<<<<< HEAD
2944

3045
return c;
3146
}
3247

3348
\*\*(For full code , refer to the .cpp file)
49+
=======
50+
51+
return c;
52+
}
53+
54+
**(For full code , refer to the .cpp file)
55+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
3456
3557
<h2>Complexity Analysis</h2>
3658
<ul>
@@ -40,3 +62,7 @@ The Tribonacci sequence is a generalization of the Fibonacci sequence, where eac
4062
<li><h3>Space Complexity: O(1)</h3>
4163
<span> - The solution uses only a constant amount of extra space.</span></li>
4264
</ul>
65+
<<<<<<< HEAD
66+
=======
67+
68+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae

‎N-th Tribonacci Number/Question.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You are given a string word. A letter is called special if it appears both in lo
44

55
Return the number of special letters in word.
66

7-
Example 1:
7+
Example - 1:
88

99
Input: word = "aaAbcBC"
1010

‎Two-sum/Approach-to-solve.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ In the given input array, nums[0] + nums[1] = 2 + 7 = 9, which matches the targe
5050
}
5151
return ans;
5252

53+
<<<<<<< HEAD
54+
=======
55+
56+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
5357
\*\*(For full code , refer to the .cpp file)
5458

5559
<h2>Complexity Analysis</h2>
@@ -61,6 +65,10 @@ In the given input array, nums[0] + nums[1] = 2 + 7 = 9, which matches the targe
6165
<span> - since we are not using any additional data structures.</span></li>
6266
</ul>
6367

68+
<<<<<<< HEAD
69+
=======
70+
71+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
6472
<hr>
6573
<h2>Approach2: Optimal Apporoach</h2>
6674
<h3>1. Optimal Solution: Using an unordered maps and 2 loops(not nested):</h3>
@@ -72,6 +80,10 @@ In the given input array, nums[0] + nums[1] = 2 + 7 = 9, which matches the targe
7280
<li>If the complement exists and it's not the same element, it adds the current index i and the index of the complement stored in the map to the result vector ans.</li>
7381
</ul>
7482
83+
<<<<<<< HEAD
84+
=======
85+
86+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
7587
<h3>Code Explanation:</h3>
7688
<ul>
7789
<li>Step 1: Initialization: <ul>
@@ -93,6 +105,10 @@ In the given input array, nums[0] + nums[1] = 2 + 7 = 9, which matches the targe
93105
94106
</ul>
95107

108+
<<<<<<< HEAD
109+
=======
110+
111+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
96112
vector<int> ans;
97113
unordered_map<int, int> hash;
98114
@@ -124,6 +140,11 @@ In the given input array, nums[0] + nums[1] = 2 + 7 = 9, which matches the targe
124140
<span> - due to the additional space required for the unordered_map.</span></li>
125141
</ul>
126142

143+
<<<<<<< HEAD
144+
=======
145+
146+
147+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
127148
<hr>
128149
<h2>Approach3: Most Optimal Apporoach: </h2>
129150
<h3>1. Optimal Solution:Using unordered_map and One For Loop:</h3>
@@ -137,6 +158,11 @@ In the given input array, nums[0] + nums[1] = 2 + 7 = 9, which matches the targe
137158
<li>Update the unordered_map hash by inserting or updating the current element nums[i] and its index i.</li></ul>
138159
</ul>
139160
161+
<<<<<<< HEAD
162+
=======
163+
164+
165+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae
140166
unordered_map<int, int> hash;
141167
vector<int> ans;
142168
@@ -161,3 +187,10 @@ In the given input array, nums[0] + nums[1] = 2 + 7 = 9, which matches the targe
161187
<li><h3>Space Complexity: O(n)</h3>
162188
<span> - due to the additional space required for the unordered_map.</span></li>
163189
</ul>
190+
<<<<<<< HEAD
191+
=======
192+
193+
194+
195+
196+
>>>>>>> ae9917feeb2a6b3a1183b7502f8a6efda2d05aae

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /