Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .vs/ISM6225_Fall_2023_Assignment_2/v17/.suo
Binary file not shown.
Binary file modified .vs/ISM6225_Fall_2023_Assignment_2/v17/.wsuo
Binary file not shown.
Binary file not shown.
186 changes: 170 additions & 16 deletions ISM6225_Fall_2023_Assignment_2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,38 @@ public static IList<IList<int>> FindMissingRanges(int[] nums, int lower, int upp
{
try
{
// Write your code here and you can modify the return value according to the requirements
return new List<IList<int>>();
IList<IList<int>> result = new List<IList<int>>();
int len = nums.Length;

if (len == 0)
{
// If there are no elements in the 'nums' array,
// add a single range from 'lower' to 'upper' to the 'result'.
result.Add(new List<int> { lower, upper });
return result;
}

if (nums[0] - lower > 0)
// If the first element of 'nums' is greater than 'lower',
// add a range from 'lower' to 'nums[0] - 1' to the 'result'.
result.Add(new List<int> { lower, nums[0] - 1 });

int i;
for (i = 1; i < len; i++)
{
if (nums[i] - nums[i - 1] > 1)
// If there's a gap between 'nums[i-1]' and 'nums[i]',
// add a range from 'nums[i-1] + 1' to 'nums[i] - 1' to the 'result'.
result.Add(new List<int> { nums[i - 1] + 1, nums[i] - 1 });
}

if (upper - nums[i - 1] > 0)
// If there's a gap between the last element of 'nums' and 'upper',
// add a range from 'nums[i-1] + 1' to 'upper' to the 'result'.
result.Add(new List<int> { nums[i - 1] + 1, upper });

return result;

}
catch (Exception)
{
Expand Down Expand Up @@ -156,8 +186,56 @@ public static bool IsValid(string s)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return s.Length == 0;
if (s.Length <= 1)
return false;

var bracketQueue = new List<int>();
for (var i = 0; i < s.Length; i++)
{
if (s[i] == '(')
{
// If an opening parenthesis is encountered, add '1' to the bracketQueue.
bracketQueue.Add(1);
continue;
}
if (s[i] == '[')
{
// If an opening square bracket is encountered, add '2' to the bracketQueue.
bracketQueue.Add(2);
continue;
}
if (s[i] == '{')
{
// If an opening curly brace is encountered, add '3' to the bracketQueue.
bracketQueue.Add(3);
continue;
}
if (bracketQueue.Count == 0)
// If there's no opening bracket to match the current closing bracket, return false.
return false;
if (s[i] == ')' && bracketQueue[bracketQueue.Count - 1] == 1)
{
// If a closing parenthesis matches the last opened parenthesis, remove it from bracketQueue.
bracketQueue.RemoveAt(bracketQueue.Count - 1);
continue;
}
if (s[i] == ']' && bracketQueue[bracketQueue.Count - 1] == 2)
{
// If a closing square bracket matches the last opened square bracket, remove it from bracketQueue.
bracketQueue.RemoveAt(bracketQueue.Count - 1);
continue;
}
if (s[i] == '}' && bracketQueue[bracketQueue.Count - 1] == 3)
{
// If a closing curly brace matches the last opened curly brace, remove it from bracketQueue.
bracketQueue.RemoveAt(bracketQueue.Count - 1);
continue;
}
// If none of the above conditions are met, return false.
return false;
}
// If all brackets are properly matched, the bracketQueue should be empty.
return bracketQueue.Count == 0;
}
catch (Exception)
{
Expand Down Expand Up @@ -191,8 +269,26 @@ public static int MaxProfit(int[] prices)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return 1;
int buy = 0, sell = 0, profit = 0;

while (sell < prices.Length)
{
// Calculate the profit by finding the maximum difference between the selling price
// at the current index and the buying price at the 'buy' index.
profit = Math.Max(prices[sell] - prices[buy], profit);

if (prices[sell] < prices[buy])
{
// If the current selling price is lower than the buying price,
// update the 'buy' index to the current 'sell' index to potentially
// find a better buying opportunity.
buy = sell;
}
sell++;
}

return profit;

}
catch (Exception)
{
Expand Down Expand Up @@ -229,8 +325,19 @@ public static bool IsStrobogrammatic(string s)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return false;
var d = new Dictionary<char, char> { { '6', '9' }, { '9', '6' }, { '8', '8' }, { '1', '1' }, { '0', '0' } };

for (int i = 0; i <= s.Length / 2; i++)
{
// Check if the character at index 'i' is in the dictionary 'd',
// and if its corresponding character at the opposite index is the same.
if (!d.ContainsKey(s[i]) || d[s[i]] != s[^(i + 1)])
return false;
}

// If all characters are valid and symmetrically matched, return true.
return true;

}
catch (Exception)
{
Expand Down Expand Up @@ -271,8 +378,18 @@ public static int NumIdenticalPairs(int[] nums)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return 0;
Dictionary<int, int> id = new(); // Initialize a dictionary to track the count of each number.
int ans = 0;

for (int i = 0; i < nums.Length; i++)
{
int c = id.GetValueOrDefault(nums[i], 0); // Get the count of the current number, default to 0 if not found.
ans += c; // Add the current count to the running sum 'ans'.
id[nums[i]] = c + 1; // Increment the count of the current number in the dictionary.
}

return ans; // Return the total count of pairs that meet the specified condition.

}
catch (Exception)
{
Expand Down Expand Up @@ -321,8 +438,18 @@ public static int ThirdMax(int[] nums)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return 0;
List<int> list = nums.Distinct().ToList(); // Remove duplicates from 'nums' and convert it to a list.
list.Sort(); // Sort the list in ascending order.

if (list.Count < 3)
{
// If there are fewer than three unique elements, return the largest element.
return list[list.Count - 1];
}

// Otherwise, return the third-largest element in the sorted list.
return list[list.Count - 3];

}
catch (Exception)
{
Expand Down Expand Up @@ -354,8 +481,22 @@ public static IList<string> GeneratePossibleNextMoves(string currentState)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return new List<string>() { };
var list = new List<string>(); // Initialize a list to store the transformed strings.
var arr = currentState.ToCharArray(); // Convert the input 'currentState' into a character array.

for (int i = 0; i < currentState.Length - 1; i++)
{
// Check for consecutive '+' symbols and replace them with '-' to create a new state.
if (arr[i] == arr[i + 1] && arr[i] == '+')
{
arr[i] = arr[i + 1] = '-'; // Transform the characters.
list.Add(new string(arr)); // Add the modified state to the list.
arr[i] = arr[i + 1] = '+'; // Restore the original state for the next iteration.
}
}

return list; // Return the list of transformed states.

}
catch (Exception)
{
Expand Down Expand Up @@ -383,8 +524,21 @@ public static IList<string> GeneratePossibleNextMoves(string currentState)

public static string RemoveVowels(string s)
{
// Write your code here and you can modify the return value according to the requirements
return "";
var set = new HashSet<char>() { 'a', 'e', 'i', 'o', 'u' }; // Initialize a set of vowels.
var sb = new StringBuilder();

foreach (var c in s)
{
// Iterate through each character in the string 's'.
if (!set.Contains(c))
{
// If the character is not in the set of vowels, append it to the StringBuilder.
sb.Append(c);
}
}

return sb.ToString(); // Return the result as a string with vowels removed.

}

/* Inbuilt Functions - Don't Change the below functions */
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = ISM6225_Fall_2023_Assignment_2
build_property.ProjectDir = C:\Users\Mounica Pothureddy\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\
build_property.ProjectDir = C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b3e1273a5bae2e691691398888e1c0c21c593bf8
a60d5bb60bb25598f134185e493d4f04d5b63ce0
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@
/Users/naveennagulapalli/Projects/ISM6225_Fall_2023_Assignment_2/ISM6225_Fall_2023_Assignment_2/obj/Debug/net7.0/ISM6225_Fall_2023_Assignment_2.pdb
/Users/naveennagulapalli/Projects/ISM6225_Fall_2023_Assignment_2/ISM6225_Fall_2023_Assignment_2/obj/Debug/net7.0/ISM6225_Fall_2023_Assignment_2.genruntimeconfig.cache
/Users/naveennagulapalli/Projects/ISM6225_Fall_2023_Assignment_2/ISM6225_Fall_2023_Assignment_2/obj/Debug/net7.0/ref/ISM6225_Fall_2023_Assignment_2.dll
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.exe
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.deps.json
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.runtimeconfig.json
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.dll
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.pdb
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.GeneratedMSBuildEditorConfig.editorconfig
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.AssemblyInfoInputs.cache
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.AssemblyInfo.cs
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.csproj.CoreCompileInputs.cache
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.dll
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\refint\ISM6225_Fall_2023_Assignment_2.dll
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.pdb
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.genruntimeconfig.cache
C:\Users\Admin\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ref\ISM6225_Fall_2023_Assignment_2.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
84e80f8aec61464260bf762f5d8ae77f9f683aa3
e8b9ba449eab6e6731d186016f0f935a7690d535
Binary file not shown.
Binary file modified ISM6225_Fall_2023_Assignment_2/obj/Debug/net7.0/apphost.exe
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
{
"format": 1,
"restore": {
"C:\\Users\\Mounica Pothureddy\\Downloads\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj": {}
"C:\\Users\\Admin\\Source\\Repos\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj": {}
},
"projects": {
"C:\\Users\\Mounica Pothureddy\\Downloads\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj": {
"C:\\Users\\Admin\\Source\\Repos\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Mounica Pothureddy\\Downloads\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj",
"projectUniqueName": "C:\\Users\\Admin\\Source\\Repos\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj",
"projectName": "ISM6225_Fall_2023_Assignment_2",
"projectPath": "C:\\Users\\Mounica Pothureddy\\Downloads\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj",
"packagesPath": "C:\\Users\\Mounica Pothureddy\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Mounica Pothureddy\\Downloads\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\obj\\",
"projectPath": "C:\\Users\\Admin\\Source\\Repos\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj",
"packagesPath": "C:\\Users\\Admin\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Admin\\Source\\Repos\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Mounica Pothureddy\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Users\\Admin\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net7.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\dotnet\\library-packs": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
Expand Down Expand Up @@ -60,7 +55,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.400\\RuntimeIdentifierGraph.json"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mounica Pothureddy\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Admin\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.6.0</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.7.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mounica Pothureddy\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
<SourceRoot Include="C:\Users\Admin\.nuget\packages\" />
</ItemGroup>
</Project>
Loading