Skip to content

Commit bfcfa10

Browse files
paramagparamag
authored andcommitted
Adding more project code
1 parent 1c3ad36 commit bfcfa10

File tree

13 files changed

+606
-1
lines changed

13 files changed

+606
-1
lines changed

Algorithm/.vs/Algorithms/v14/.suo

31.5 KB
Binary file not shown.

Algorithm/Algorithms.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alogrithms.Problem.DynamicP
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Algorithms.Problems.LeetCode", "LeetCode\Algorithms.Problems.LeetCode.csproj", "{C66BCA6A-F2B5-467B-89E9-61C228639298}"
2323
EndProject
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Algorithms.Problem.InterviewCake", "InterviewCake\Algorithms.Problem.InterviewCake.csproj", "{9618162B-F6BE-4E79-A256-8B2D34AE7F46}"
25+
EndProject
2426
Global
2527
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2628
Debug|Any CPU = Debug|Any CPU
@@ -161,6 +163,22 @@ Global
161163
{C66BCA6A-F2B5-467B-89E9-61C228639298}.Release|x64.Build.0 = Release|Any CPU
162164
{C66BCA6A-F2B5-467B-89E9-61C228639298}.Release|x86.ActiveCfg = Release|Any CPU
163165
{C66BCA6A-F2B5-467B-89E9-61C228639298}.Release|x86.Build.0 = Release|Any CPU
166+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|Any CPU.Build.0 = Debug|Any CPU
168+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|ARM.ActiveCfg = Debug|Any CPU
169+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|ARM.Build.0 = Debug|Any CPU
170+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|x64.ActiveCfg = Debug|Any CPU
171+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|x64.Build.0 = Debug|Any CPU
172+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|x86.ActiveCfg = Debug|Any CPU
173+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Debug|x86.Build.0 = Debug|Any CPU
174+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|Any CPU.ActiveCfg = Release|Any CPU
175+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|Any CPU.Build.0 = Release|Any CPU
176+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|ARM.ActiveCfg = Release|Any CPU
177+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|ARM.Build.0 = Release|Any CPU
178+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|x64.ActiveCfg = Release|Any CPU
179+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|x64.Build.0 = Release|Any CPU
180+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|x86.ActiveCfg = Release|Any CPU
181+
{9618162B-F6BE-4E79-A256-8B2D34AE7F46}.Release|x86.Build.0 = Release|Any CPU
164182
EndGlobalSection
165183
GlobalSection(SolutionProperties) = preSolution
166184
HideSolutionNode = FALSE
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{9618162B-F6BE-4E79-A256-8B2D34AE7F46}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Algorithms.Problem.InterviewCake</RootNamespace>
11+
<AssemblyName>Algorithms.Problem.InterviewCake</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
34+
<SpecificVersion>False</SpecificVersion>
35+
<HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll</HintPath>
36+
</Reference>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Net.Http" />
44+
<Reference Include="System.Xml" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="AppStockProblem.cs" />
48+
<Compile Include="PlayGround.cs" />
49+
<Compile Include="Meeting.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
<Compile Include="RepeatNumbers.cs" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
58+
Other similar extension points exist, see Microsoft.Common.targets.
59+
<Target Name="BeforeBuild">
60+
</Target>
61+
<Target Name="AfterBuild">
62+
</Target>
63+
-->
64+
</Project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Algorithms.Problem.InterviewCake
9+
{
10+
[TestClass]
11+
public class AppStockProblem
12+
{
13+
public int FindBestStock(int[] stockPrices)
14+
{
15+
int max_Profit_sofar = int.MinValue;
16+
int j = 0;
17+
for (int i = 1; i < stockPrices.Length; i++)
18+
{
19+
if (max_Profit_sofar < stockPrices[i] - stockPrices[j])
20+
{
21+
max_Profit_sofar = stockPrices[i] - stockPrices[j];
22+
}
23+
else
24+
{
25+
j = i;
26+
}
27+
}
28+
29+
return max_Profit_sofar;
30+
}
31+
32+
[TestMethod]
33+
public void TestStockProblem()
34+
{
35+
int expectedProfit = -1;
36+
int bestProfit = this.FindBestStock(new[] { 9, 7, 4, 1, 6 });
37+
38+
Assert.AreEqual(expectedProfit, bestProfit, "Expected and Actual are wrong!");
39+
}
40+
}
41+
}

Algorithm/InterviewCake/Meeting.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Algorithms.Problem.InterviewCake
9+
{
10+
[TestClass]
11+
public class Meeting
12+
{
13+
public Meeting() { }
14+
15+
public int StartTime { get; set; }
16+
17+
public int EndTime { get; set; }
18+
19+
public Meeting(int startTime, int endTime)
20+
{
21+
// Number of 30 min blocks past 9:00 am
22+
StartTime = startTime;
23+
EndTime = endTime;
24+
}
25+
26+
public override bool Equals(object obj)
27+
{
28+
if (obj == null || GetType() != obj.GetType())
29+
{
30+
return false;
31+
}
32+
33+
if (ReferenceEquals(obj, this))
34+
{
35+
return true;
36+
}
37+
38+
var meeting = (Meeting)obj;
39+
return StartTime == meeting.StartTime && EndTime == meeting.EndTime;
40+
}
41+
42+
public override int GetHashCode()
43+
{
44+
var result = 17;
45+
result = result * 31 + StartTime;
46+
result = result * 31 + EndTime;
47+
return result;
48+
}
49+
50+
public override string ToString()
51+
{
52+
return $"({StartTime}, {EndTime})";
53+
}
54+
55+
public static List<Meeting> MergeRanges(List<Meeting> meetings)
56+
{
57+
// Meeting(1,3) overlaps with Meeting(2,4) Merge to Meeting(1,4)
58+
// SO, if the end time is greater than the start time of next then merge the two meetings.
59+
60+
// Sort the original meeting requests by start time.
61+
var sortedMeetingList = meetings
62+
.Select(m => new Meeting(m.StartTime, m.EndTime))
63+
.OrderBy(m => m.StartTime);
64+
65+
// Initialize the new list to the first item in the sorted list.
66+
IList<Meeting> ouputMeetingList = new List<Meeting> { sortedMeetingList.First() };
67+
68+
foreach (var meeting in sortedMeetingList)
69+
{
70+
// get the lastly added item to the output list.
71+
var lastAddedMeeting = ouputMeetingList.Last();
72+
73+
// If the start time of the incoming list is less than the end time of the existing list.
74+
// As it is ordered by start time, we can merge to the existing list.
75+
if (meeting.StartTime <= lastAddedMeeting.EndTime)
76+
{
77+
// Update the end time to the max end time of both the meeting request.
78+
// For instance Meeting(1,3), the new meeting could be Meeting(1,2) => result should be Meeting (1,3)
79+
// Second case: Meeting(1,3), the new meeting coule be Meeting(2, 4) => result should be Meeting (1,4)
80+
lastAddedMeeting.EndTime = Math.Max(meeting.EndTime, lastAddedMeeting.EndTime);
81+
}
82+
else
83+
{
84+
ouputMeetingList.Add(meeting);
85+
}
86+
}
87+
88+
return ouputMeetingList.ToList();
89+
}
90+
91+
[TestMethod]
92+
public void MeetingsOverlapTest()
93+
{
94+
var meetings = new List<Meeting>()
95+
{
96+
new Meeting(1, 3), new Meeting(2, 4)
97+
};
98+
var actual = MergeRanges(meetings);
99+
var expected = new List<Meeting>()
100+
{
101+
new Meeting(1, 4)
102+
};
103+
Assert.AreEqual(expected.Count, actual.Count);
104+
}
105+
}
106+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Algorithms.Problem.InterviewCake
9+
{
10+
[TestClass]
11+
public class PlayGround
12+
{
13+
public ISet<string> GetPermutations(string inputString)
14+
{
15+
// Base case
16+
if (inputString.Length <= 1)
17+
{
18+
return new HashSet<string>(inputString.Select(c => new string(c, 1)));
19+
}
20+
21+
var allCharsExceptLast = inputString.Substring(0, inputString.Length - 1);
22+
char lastChar = inputString[inputString.Length - 1];
23+
24+
// Recursive call: get all possible permutations for all chars except last
25+
var permutationsOfAllCharsExceptLast = GetPermutations(allCharsExceptLast);
26+
27+
// Put the last char in all possible positions for each of the above permutations
28+
var permutations = new HashSet<string>();
29+
foreach (var permutationOfAllCharsExceptLast in permutationsOfAllCharsExceptLast)
30+
{
31+
for (int position = 0; position <= allCharsExceptLast.Length; position++)
32+
{
33+
var permutation = permutationOfAllCharsExceptLast.Substring(0, position)
34+
+ lastChar
35+
+ permutationOfAllCharsExceptLast.Substring(position);
36+
permutations.Add(permutation);
37+
}
38+
}
39+
40+
return permutations;
41+
}
42+
43+
[TestMethod]
44+
public void TestPermutations()
45+
{
46+
GetPermutations("cats");
47+
}
48+
}
49+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("InterviewCake")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("InterviewCake")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("9618162b-f6be-4e79-a256-8b2d34ae7f46")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)