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 added ISM6225_Fall_2023_Assignment_2/DIS_Assig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
198 changes: 173 additions & 25 deletions ISM6225_Fall_2023_Assignment_2/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/*

YOU ARE NOT ALLOWED TO MODIFY ANY FUNCTION DEFINATION's PROVIDED.
WRITE YOUR CODE IN THE RESPECTIVE QUESTION FUNCTION BLOCK


*/

using System;
using System.Text;
using System.Collections.Generic;

namespace ISM6225_Fall_2023_Assignment_2
{
Expand All @@ -24,6 +18,7 @@ static void Main(string[] args)
Console.WriteLine();
Console.WriteLine();


//Question2:
Console.WriteLine("Question 2");
string parenthesis = "()[]{}";
Expand Down Expand Up @@ -112,16 +107,50 @@ 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>>();
// Initialize a list to store the missing ranges
IList<IList<int>> result = new List<IList<int>>();

// Convert 'lower' and 'upper' to long to prevent integer overflow
long lowerLong = (long)lower;
long upperLong = (long)upper;

// Iterate through the elements in the 'nums' array
for (int i = 0; i < nums.Length; i++)
{
if (nums[i] > lowerLong) // If the current number is greater than 'lower', it indicates a missing range
{
if (nums[i] == lowerLong + 1) // Check if the missing range is just one number
{
result.Add(new List<int> { (int)lowerLong });
}
else
{
result.Add(new List<int> { (int)lowerLong, nums[i] - 1 }); // Add a range from 'lowerLong' to 'nums[i] - 1' to 'result'
}
}
if (nums[i] == upperLong) // nums[i] is equal to upper as well
{
return result;
}
lowerLong = (long)nums[i] + 1;
}

if (lowerLong <= upperLong)
{
result.Add(new List<int> { (int)lowerLong, (int)upperLong });
}

return result;
}
catch (Exception)
{

throw;
}

}



/*

Question 2
Expand Down Expand Up @@ -156,8 +185,28 @@ 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;
Stack<char> stack = new Stack<char>();

foreach (char c in s)
{
if (c == '(' || c == '{' || c == '[') // Check if the character is an opening bracket '(', '{', or '['
{
stack.Push(c); // If it's an opening bracket, push it onto the stack
}
else
{
// If it's not an opening bracket, it must be a closing bracket
if (stack.Count == 0)
return false;

char top = stack.Pop();

if ((c == ')' && top != '(') || (c == '}' && top != '{') || (c == ']' && top != '[')) // Check if the current closing bracket matches the last opening bracket
return false;
}
}

return stack.Count == 0;
}
catch (Exception)
{
Expand Down Expand Up @@ -191,11 +240,35 @@ public static int MaxProfit(int[] prices)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return 1;
// Check if the 'prices' array is null or has fewer than 2 elements
if (prices == null || prices.Length < 2)
{
return 0; // If there are not enough prices, there can be no profit
}

int maxProfit = 0; // Initialize the maximum profit to zero
int minPrice = prices[0]; // Initialize the minimum price to the first element

// Iterate through the 'prices' array starting from the second element
for (int i = 1; i < prices.Length; i++)
{
if (prices[i] < minPrice)
{
// If the current price is lower than the minimum, update the minimum price
minPrice = prices[i];
}
else if (prices[i] - minPrice > maxProfit)
{
// If selling at the current price results in a higher profit, update maxProfit
maxProfit = prices[i] - minPrice;
}
}

return maxProfit;
}
catch (Exception)
{

throw;
}
}
Expand Down Expand Up @@ -229,8 +302,30 @@ public static bool IsStrobogrammatic(string s)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return false;
// Define a dictionary to store the valid strobogrammatic pairs
Dictionary<char, char> strobogrammaticPairs = new Dictionary<char, char>
{
{'0', '0'},
{'1', '1'},
{'6', '9'},
{'8', '8'},
{'9', '6'}
};

int left = 0; // Initialize the left pointer at the start of the string
int right = s.Length - 1; // Initialize the right pointer at the end of the string

while (left <= right) // Iterate through the string from both ends toward the center
{
if (!strobogrammaticPairs.ContainsKey(s[left]) || s[right] != strobogrammaticPairs[s[left]]) // Check if the character at the left position exists in the strobogrammaticPairs
{
return false; // If not a valid pair, the string is not strobogrammatic
}
left++; // Move the left pointer to the right
right--; // Move the right pointer to the left
}

return true;
}
catch (Exception)
{
Expand Down Expand Up @@ -271,8 +366,23 @@ public static int NumIdenticalPairs(int[] nums)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return 0;
int count = 0; // Initialize a variable to count the number of good pairs
Dictionary<int, int> frequencyMap = new Dictionary<int, int>(); // Create a dictionary to store the frequency of each number

foreach (int num in nums) // Iterate through the array of numbers
{
if (frequencyMap.ContainsKey(num)) // If the number already exists in the frequencyMap, it means there's a pair.
{
count += frequencyMap[num]; // Increment the count by the number of occurrences of that number in the array.
frequencyMap[num]++; // Increment the frequency of the number in the frequencyMap.
}
else
{
frequencyMap[num] = 1; // If the number doesn't exist in the frequencyMap, initialize its frequency to 1.
}
}

return count;
}
catch (Exception)
{
Expand Down Expand Up @@ -321,8 +431,23 @@ public static int ThirdMax(int[] nums)
{
try
{
// Write your code here and you can modify the return value according to the requirements
return 0;
SortedSet<int> uniqueNums = new SortedSet<int>();

foreach (int num in nums)
{
uniqueNums.Add(num);
if (uniqueNums.Count > 3) // Iterate through the input array 'nums'
{
uniqueNums.Remove(uniqueNums.Min); // Add each number to the 'uniqueNums' set
}
}

if (uniqueNums.Count < 3) // If the number of unique numbers exceeds 3, remove the smallest element.
{
return uniqueNums.Max; // If 'uniqueNums' contains fewer than 3 elements, return the maximum element.
}

return uniqueNums.Min; // Return the minimum element, which is the third maximum number.
}
catch (Exception)
{
Expand Down Expand Up @@ -354,8 +479,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>() { };
IList<string> result = new List<string>(); // Create a list to store possible next states

for (int i = 0; i < currentState.Length - 1; i++) // Iterate through the input string 'currentState'
{
if (currentState[i] == '+' && currentState[i + 1] == '+') // Check for consecutive "++" substrings
{
char[] newState = currentState.ToCharArray(); // Convert the current state to a character array

// Flip the consecutive "++" into "--" by changing the corresponding characters
newState[i] = '-';
newState[i + 1] = '-';
result.Add(new string(newState)); // Add the updated state to the 'result' list
}
}

return result;
}
catch (Exception)
{
Expand Down Expand Up @@ -383,8 +522,17 @@ 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 "";
StringBuilder result = new StringBuilder(); // Create a StringBuilder to store the resulting string

foreach (char c in s)
{
if ("aeiouAEIOU".IndexOf(c) == -1) // Check if the current character 'c' is not a vowel (not found in "aeiouAEIOU")
{
result.Append(c); // Append the character to the 'result' if it's not a vowel
}
}

return result.ToString(); // Convert the StringBuilder to a string and return the result
}

/* 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\himan\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\himan\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.exe
C:\Users\himan\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\himan\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\himan\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.dll
C:\Users\himan\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\bin\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.pdb
C:\Users\himan\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\himan\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\himan\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\himan\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\himan\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.dll
C:\Users\himan\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\himan\Source\Repos\ISM6225_Fall_2023_Assignment_2\ISM6225_Fall_2023_Assignment_2\obj\Debug\net7.0\ISM6225_Fall_2023_Assignment_2.pdb
C:\Users\himan\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\himan\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
1d21740c59626934e95580837e45833927ba9358
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\\himan\\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\\himan\\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\\himan\\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\\himan\\Source\\Repos\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2\\ISM6225_Fall_2023_Assignment_2.csproj",
"packagesPath": "C:\\Users\\himan\\.nuget\\packages\\",
"outputPath": "C:\\Users\\himan\\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\\himan\\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\himan\.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\himan\.nuget\packages\" />
</ItemGroup>
</Project>
Loading