View promotion_solution_knapsack_01.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
//Idea: | |
//1. Sort the list by input descending | |
//2. Get all inputs of the list item after sorted | |
//3. Get indexes list of item want to pick | |
//4. For each index in the list, get item at that index | |
//Time complexcity Worst case: O(N * Sum). N is the length of the array. Sum is the total value of the array |
View promotion_solution_knapsack_01.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace KnapsackForPromotion | |
{ | |
//Idea: | |
//1. Sort the list by input descending (this is for the case we found (7,5) and (6,6) but we pick (6,6)) | |
//2. Get all inputs of the list item after sorted | |
//3. Get indexes list of item want to pick |
View CountTripletsSolution.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Complete the countTriplets function below. | |
fun countTriplets(arr: Array<Long>, r: Long): Long { | |
var befMap = HashMap<Long, Int>() | |
var aftMap = HashMap<Long, Int>() | |
for(num in arr) { | |
if(aftMap.containsKey(num)) aftMap[num] = aftMap[num]!! + 1 | |
else aftMap[num] = 1 | |
} | |
View FluentBindingAdapterMvxRecyclerView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PersonItemAdapter : MvxRecyclerAdapter | |
{ | |
public PersonItemAdapter(IMvxAndroidBindingContext bindingContext) | |
: base(bindingContext) | |
{ | |
} | |
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) | |
{ | |
var itemBindingContext = new MvxAndroidBindingContext(parent.Context, BindingContext.LayoutInflaterHolder); |
View product.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity(tableName = "products") | |
data class Product( | |
@PrimaryKey | |
@NonNull | |
@ColumnInfo(name = "productId") | |
val id: String, | |
@ColumnInfo(name = "name") | |
var name: String?, | |
View LineItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity(tableName = "line_items") | |
data class LineItem( | |
@PrimaryKey(autoGenerate = true) | |
@ColumnInfo(name = "lineItemId") | |
val id: Long, | |
@ColumnInfo(name = "productId") | |
val productId: String, | |
@ColumnInfo(name = "orderId") |
View order.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity(tableName = "orders") | |
data class Order( | |
@PrimaryKey | |
@ColumnInfo(name = "orderId") | |
val id: String, | |
@ColumnInfo(name = "status") | |
var status: String, | |
@ColumnInfo(name = "address") |
View LineItemAndProduct.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class LineItemAndProduct( | |
@Embedded val lineItem: LineItem?, | |
@Relation( | |
parentColumn = "productId", | |
entityColumn = "productId", | |
entity = Product::class | |
) | |
val product: Product? | |
) |
View OrderWithLineItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class OrderWithLineItems( | |
@Embedded var order: Order, | |
@Relation( | |
parentColumn = "orderId", | |
entityColumn = "orderId", | |
entity = LineItem::class | |
) | |
val lineItemList: MutableList<LineItemAndProduct> | |
) |
View LineItemDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface LineItemDao { | |
//Get all line item in along with its product | |
@Transaction | |
@Query("SELECT * FROM line_items ") | |
fun getAll(): Flow<List<LineItemAndProduct>> | |
//Get line item in an order by orderId | |
@Transaction | |
@Query("SELECT * FROM line_items WHERE orderId = :orderId") |
OlderNewer