instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Implement a shell sort algorithm in Python that sorts an array of integers in ascending order.
Requirements:
- The time complexity of your solution should be O(n^2).
- You are not allowed to use any built-in sorting functions or libraries.
- Your implementation should be in-place, i.e., it should not create a new arra... | codefeedback |
Write a Python program to find all the prime numbers in the range between 1 to 1000 and print the sum of all the prime numbers found. | codefeedback |
Create a function to check if a string contains only unique characters without using any additional data structures. The function should have a time complexity of O(n^2) and should not use any built-in library functions. The string will only contain lowercase alphabets.
string = "programming" | codefeedback |
Create a Java program to print a square diamond pattern with '*' characters. However, the program should also include a method to check if a given number is prime and only print the diamond pattern if the input number is prime. | codefeedback |
Write a C program that takes an integer as input and prints the sum of all its digits. The program should handle negative numbers and ignore any non-digit characters present in the input. The input number will be within the range of -10^9 to 10^9. | codefeedback |
Write a SQL query that counts the number of customers by country and orders the result by the number of customers in descending order. Additionally, include only countries with more than 1 customer in the result.
Table: Customers
+----+------------+------------+-----------+
| Id | First Name | Last Name | Country |... | codefeedback |
Write a function in Python that takes in two lists of integers and returns the lengths of the lists, the values that are common in both lists, and the count of common values. Additionally, the function should raise a ValueError if either of the input lists contains duplicate values. list1 = [1, 2, 3, 4, 6] list2 = [2, ... | codefeedback |
Create a JavaScript function for sorting an array of numbers in ascending order using the merge sort algorithm.
Additional Requirements:
- The time complexity of the sorting function should be O(n log n).
- The space complexity of the sorting function should be O(n).
- Do not use any built-in sorting functions or libr... | codefeedback |
Explain how a Depth-First-Search (DFS) algorithm works, and provide a step-by-step explanation of how the algorithm traverses a graph. Additionally, discuss the time and space complexity of the DFS algorithm and provide examples of real-life scenarios where DFS can be applied effectively. | codefeedback |
Write a SQL statement to select all rows in a table and order them in descending order based on a specific column.
Table name: student_info
Column name: GPA | codefeedback |
Convert the string in the given variable to lowercase and remove any special characters. Additionally, count the number of vowels in the resulting string.
String: "HELLO WORLD!!!" | codefeedback |
Write a SQL query to find all books in the library with the title "Harry Potter" that were published in the last 5 years. | codefeedback |
Create a JavaScript function that takes an array of numbers as parameter and returns the second smallest prime number in it. | codefeedback |
Reverse a linked list of integers and output the result. The input will be provided as a head node of the linked list.
#Additional Information#
1. The linked list node is defined as follows:
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
2. The in... | codefeedback |
Write a JavaScript program to find out the day of the week for a given date, taking into account the Julian calendar system.
Date: October 15, 1582 | codefeedback |
Create a Python class "Point" that has two instance variables x and y. Implement a method called "distance_to_origin" that calculates the distance between the point and the origin (0,0) using the Pythagorean theorem. Additionally, the class should have a method called "translate" that takes in two parameters dx and dy ... | codefeedback |
Convert a JSON string to an XML string with the following conditions:
1. Preserve the hierarchy of the JSON data in the XML.
2. Convert JSON key-value pairs to XML elements and attributes.
3. Handle nested JSON objects and arrays appropriately in the XML structure.
4. Use specific XML tags for different data types, suc... | codefeedback |
Generate a list with the numbers from 1 to 10 in reverse order using Python. | codefeedback |
Write a SQL statement to select customers who have placed an order within the last 30 days and have also made at least 3 previous orders in the past year. | codefeedback |
Design a function to convert a given numerical grade to a corresponding letter grade, but with the following additional requirements:
- The function should only accept numerical grades within the range of 0 to 100 (inclusive).
- The function should handle both integer and floating-point input grades.
- The function sho... | codefeedback |
Generate an SQL statement to select the top 10 most expensive items from a table named "products" that were sold between a specific date range. | codefeedback |
Convert the following function to use the reduce method in Python. You are not allowed to use any other built-in Python functions or methods, such as sum() or any other higher-order functions.
def sum_list(nums):
total = 0
for num in nums:
total += num
return total | codefeedback |
Create a responsive HTML form with three text fields (First Name, Last Name and Email) that includes client-side form validation to ensure that all fields are filled out correctly. Additionally, implement a server-side validation that checks if the email entered is unique and not already registered in the system. | codefeedback |
Write a query in elasticsearch that returns documents that contain matching content. Find all documents in the "products" index that contains the phrase "Black Friday" and have a minimum price of $100. | codefeedback |
Generate a correct C++ class definition to fulfill the following tasks.
Create a class that has four member variables: a, b, c and d.
The variable a should be of type integer, b should be of type float, c should be of type string and d should be of type boolean.
Additionally, the class should have a constructor that ta... | codefeedback |
Devise a programming logic to find the sum of the first 1000 prime numbers. | codefeedback |
Devise a logic using PHP to check if a number is prime. Additionally, the solution should not use any built-in PHP functions for prime number checking. | codefeedback |
Write a function in Python to merge two sorted arrays in descending order.
arr1 = [9, 5, 1]
arr2 = [8, 6, 3, 2] | codefeedback |
Suggest a way to optimize a given code segment.
x = 0
for i in range(100):
for j in range(100):
x = x + i + j
#Reference Code#
Suggest a way to optimize a given code segment.
x = 0
for i in range(100):
for j in range(100):
x = x + i * j
#Rewritten Test# | codefeedback |
Implement a function in Pandas that handles missing data by interpolating the missing values based on the values of neighboring data points. The function should have a time complexity of O(n) and should be able to handle datasets with up to 1 million rows. | codefeedback |
Create a React component that displays a search bar with autocomplete functionality.
Requirements:
1. The search bar should have an input field and a button.
2. The autocomplete functionality should suggest possible search terms as the user types in the input field.
3. The suggestions should be displayed in a dropdown... | codefeedback |
Debug the following C code so that it compiles and runs successfully. Your solution should also include the following additional requirements:
1. The code should utilize at least one user-defined function.
2. The program should take user input to display a personalized greeting message.
3. The program should display th... | codefeedback |
Write a function in Java to find the length of the longest common subsequence of two strings. The strings can contain both uppercase and lowercase letters, as well as special characters. The function should also return the actual longest common subsequence itself. | codefeedback |
Implement a binary classification model using Support Vector Machines (SVM) to predict the likelihood of a customer subscribing to a bank's term deposit based on historical customer data. Evaluate the model's performance using precision, recall, and F1-score metrics, and plot a ROC curve to visualize the model's classi... | codefeedback |
Write a function that takes in a list of integers and an element, and returns the index of the first occurrence of the element in the list. The function should handle cases where the element is not present in the list and return -1 in such cases. The input list should have a length of at least 3. The function should on... | codefeedback |
Explain what a Monadic function is and provide an example implementation in a programming language of your choice. Additionally, discuss the advantages and disadvantages of using Monadic functions in software development. | codefeedback |
Compare inheritance and composition in Python and provide a code example showcasing the difference between them. | codefeedback |
Debug the following code to print a list of all prime numbers between 1 and 100,000,000 using the Miller-Rabin primality test algorithm. | codefeedback |
Write a code to print out all dates between two given dates in Python, with the following additional requirements:
- The code should be able to handle any valid date format.
- The start_date and end_date can be in any order.
- The code should handle leap years correctly.
- The code should be efficient and not use exces... | codefeedback |
Develop a python code to sort an array of numbers using only recursion. | codefeedback |
Generate a Java program that prints the longest word in a sentence, considering that the sentence may contain multiple words with the same length. If there are multiple longest words, the program should print all of them. | codefeedback |
Generate a jQuery code snippet to create a div and assign it a class of "main". Then, create an event handler that listens for a click event on the div and changes its background color to red when clicked. | codefeedback |
Create a recursive algorithm to sum the numbers between 1 and n (inclusive), but exclude any number that is divisible by 3.
n = 5 | codefeedback |
Create a code to generate a unique 7-character string of random numbers and letters, ensuring that no two generated strings are the same. | codefeedback |
Write a Java program to print the Fibonacci sequence up to the limit of n, where n is a positive integer provided by the user. The program should include error handling to ensure that the user enters a valid positive integer. Additionally, the program should use recursion to generate the Fibonacci sequence. | codefeedback |
Create a function that takes in a list of integers and a target integer as parameters. The function should search the list and return the first index at which the target integer is found, or -1 if the target integer does not exist in the list.
For example, given the list [1, 2, 3] and the target integer 3, the functi... | codefeedback |
Find all substrings of length 3 or more in the given string and remove any duplicates.
Input: "googleeee" | codefeedback |
Create a program that counts the number of unique words in a sentence, excluding any common stopwords. The program should also handle cases where the sentence contains punctuation marks and special characters. The program should be efficient and have a time complexity of O(n), where n is the length of the sentence. | codefeedback |
Given a string, concatenate the first and last character of the string together. Additionally, if the length of the string is odd, remove the middle character before concatenating. | codefeedback |
Write a function that calculates the factorial of a given number. The factorial of a number n is the product of all positive integers less than or equal to n. For example, the factorial of 4 (denoted as 4!) is calculated as 4 * 3 * 2 * 1, which equals 24. | codefeedback |
Construct a Bash script that displays the current date and time in the format "YYYY-MM-DD HH:MM:SS". Additionally, the script should prompt the user to enter their name, and then display a personalized greeting message along with the date and time. | codefeedback |
Create a function that refreshes a web page until an element with the given ID becomes visible. Additionally, the function should handle scenarios where the element does not exist or is not visible even after refreshing multiple times.
To accomplish this, the function should have the following logic steps:
1. Accept ... | codefeedback |
Edit the given code to remove compile time error and improve the functionality.
def add_two_numbers(a, b):
return a + b
#Additional Instructions#
1. Use type annotations in the function definition to specify that the parameters 'a' and 'b' are integers.
2. Implement input validation to ensure that the arguments pa... | codefeedback |
Write a function in Python to print out the elements of a given array in reverse order without using any built-in functions or libraries such as reverse(). The function should only use basic logical steps and loops to solve the problem efficiently.
Example Input:
array = [1,2,3,4,5]
Expected Output:
5
4
3
2
1 | codefeedback |
Create a Python script to scrape all links from a web page, while ensuring that the links are unique and not duplicate.
The script should also implement a breadth-first search algorithm to crawl through multiple levels of pages, starting from the given web page. The depth of crawling should be user-defined.
Additiona... | codefeedback |
Write a C# code to print an array in reverse order, but you are not allowed to use any built-in array reversal methods or create a new array to store the reversed elements. The solution must be done in-place by manipulating the original array. int[] numbers = {1,2,3,4}; | codefeedback |
Create an HTML form to display a list of countries and its corresponding capital, with the following additional requirements:
1. The form should allow users to add new countries and capitals to the list dynamically.
2. The form should validate that the user has entered a valid country and capital before adding them to... | codefeedback |
Write a SQL query to select the names of all the students from the table "students" whose age is greater than 18 and whose GPA is above 3.5. | codefeedback |
Write a Java method to insert a given string at the beginning of every word in a given sentence. The given sentence can contain special characters, numbers, and multiple consecutive spaces between words. The inserted string should be enclosed in square brackets.
Example:
Input:
String sentence = "The quick brown fo... | codefeedback |
Create an Angular component that displays information about a user and allows the user to update their information.
const user = {
id: 1,
name: 'Bob',
age: 23,
email: 'bob@example.com'
};
The component should have the following features:
1. Display the user's name, age, and email in separate HTML elements... | codefeedback |
Using a loop, output all the even numbers up to the given number n. Additionally, the program should skip any number that is divisible by 3. The program should also calculate and output the sum of all the even numbers. Finally, the program should keep track of the total count of even numbers and output it at the end.
n... | codefeedback |
Name the most common relational database management systems and their respective query languages. | codefeedback |
Write an algorithm in Python to search for the first non-repeating element in a given array. The array may contain both positive and negative integers. The array may also contain duplicate elements. If there are no non-repeating elements, return None.
Example:
array = [4, 6, -4, 1, 8, 6, 44, -21]
Output: -4
Note:
In ... | codefeedback |
Create an HTML input form to collect user information, including the following constraints: the form must have at least 5 input fields, one of which must be a dropdown menu; the form must include a validation mechanism to ensure that all fields are filled out before submission; the form must be styled using CSS to have... | codefeedback |
List the four basic types of loops in JavaScript and provide an example code snippet showcasing each type. | codefeedback |
Design an advanced color palette for a website with seven colors, where each color must be a shade of a primary color (red, blue, or yellow) and must be chosen using the HSL (Hue, Saturation, Lightness) color model. | codefeedback |
Write a code in SQL to create a database table that stores the names, scores, and subject grades of students in a class. The subject grades should be calculated based on the scores using the following criteria:
- A score above 90 should be given an 'A' grade.
- A score between 80 and 89 should be given a 'B' grade.
- A... | codefeedback |
Generate a code in R to remove spaces and punctuation from a given string, while also converting all characters to lowercase. The given string should contain at least one alphanumeric character. The given string is "Hello, World.". | codefeedback |
Create a class called "BankAccount" in Java with instance variables for the account number, name, balance, and transaction history.
The BankAccount class should have the following methods:
- A constructor that takes parameters for the account number, name, and balance, and initializes the instance variables.
- Getter ... | codefeedback |
Create a JavaScript code to validate the syntax of a given string, considering the following rules:
1. The given string must contain at least one uppercase letter, one lowercase letter, and one special character.
2. The length of the given string must be between 8 and 20 characters.
3. The given string must not contain... | codefeedback |
Explain the concept of variable scoping in JavaScript and provide an example code snippet that demonstrates how variable scoping works in different scopes. | codefeedback |
Given a list of numbers, write a function to check for odd numbers and return a new list containing only the odd numbers found. The function should also display a message stating the number of odd numbers found and their positions in the original list.
Example:
Input:
my_list = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
... | codefeedback |
Describe how dynamic programming works in programming. Provide an efficient implementation in a language of your choice that uses memoization to solve a problem of finding the maximum sum of a subarray in an array of integers. The implementation should handle arrays of size up to 10^6 and should have a time complexity ... | codefeedback |
Write a function in Python to check if a string consists of only lowercase alphabetic characters. | codefeedback |
Explain in your own words what APIs are and provide an example of how they are commonly used in a programming context. | codefeedback |
Write a code to generate a random password consisting of 8 characters with atleast one lowercase letter, one uppercase letter, one number, and one special character. The password should also not contain any repeating characters. | codefeedback |
Create a program that prints out a triangle of stars with a user-defined height, where the height must be a positive integer between 1 and 10. The program should also ask the user for the symbol used to represent the stars, which can be any printable ASCII character. The triangle should be printed with each row contain... | codefeedback |
Create a MongoDB collection named "users" with 2 fields called "name" and "age". The "name" field should store a string of length 10 characters and the "age" field should store an integer between 1 and 100 (inclusive). Additionally, implement a function that generates 10,000 random user documents and inserts them into ... | codefeedback |
Create a function in JavaScript that takes an array as input and returns a new array containing only the unique values from the original array. The input array can contain both numbers and strings. Make sure to handle edge cases and optimize the code for efficiency. | codefeedback |
Specify an appropriate condition that limits the set of documents produced based on the given context.
In a newsreader application, train a classifier to pull out only the articles about current world news, but exclude articles about politics and sports. | codefeedback |
Write a JavaScript function to compare two numbers and return a boolean value. Additionally, the function should return true if the first number is divisible by the second number without any remainder, and false otherwise. | codefeedback |
Write a query to select the first 3 characters of every row from a column called 'name' from a PostgreSQL table, but exclude any rows where the first character is a vowel. | codefeedback |
Remove the given function from the code and replace it with a lambda expression that accepts only positive integers and returns their product multiplied by three. | codefeedback |
Given a BST, write a function to find the number of values greater than the root node. Additionally, find the number of values greater than each node in the BST.
25
/ \
15 35
/ \ / \
10 20 30 40
Output: [4, 3, 2, 1, 2, 1, 0, 0] | codefeedback |
Design a URL shortening system where a given URL is converted to an 8 digit alphanumeric string. The system should also be able to handle a maximum of 100,000 URLs at any given time and provide a real-time analytics dashboard to monitor the number of clicks each shortened URL receives. | codefeedback |
Implement a function that takes a string as a parameter and returns a modified string with the words reversed. Additionally, the function should remove any leading or trailing whitespace from the input string before processing.
For example, if the input string is " This is a sentence. ", the function should return... | codefeedback |
Calculate the average of the numbers in the given list, but only consider the numbers that are divisible by 3 and greater than 10.
numbers = [2, 10, 15, 20, 25, 30] | codefeedback |
Compute the standard deviation of the given array, but exclude any negative numbers from the calculation.
data = [10, -15, 20, -25, 30] | codefeedback |
Given two input strings s and t, find the length of the longest common substring that starts and ends with the same character.
s = "abcde"
t = "acfgh" | codefeedback |
Usage of Global Variable and Recursion
## Problem Statement ##
You are given a list of integers, `nums`, and an integer, `target`.
Write a function, `find_combinations(nums: List[int], target: int) -> int`, that will return the number of distinct combinations of the given integers that sum up to the target.
You ma... | codefeedback |
Compute the Minkowski distance between two lists, where each list can contain up to 10^6 elements.
list_1 = [1, 2, 3, ..., 10^6]
list_2 = [-1, -2, -3, ..., -10^6] | codefeedback |
Write a SQL query to return rows that contain latitude greater than 50 and longitude less than -100. | codefeedback |
Find the maximum value in a given array of integers, but without using any built-in array functions or sorting algorithms.
[4, 6, 9, 11, 15] | codefeedback |
Create a JavaScript class to represent a rectangle with properties for width and height. The class should also have a method to calculate the area of the rectangle and a method to check if it is a square. | codefeedback |
Create a function to convert a positive integer to its binary representation using a recursive approach. The function should have a time complexity of O(log n), where n is the given integer.
Example:
Input: 15
Output: "1111" | codefeedback |
Write a function called "calculate_sum" that takes in a list of integers as a parameter and returns the summation of all elements in the list. The function should also handle empty lists by returning 0.
list1 = [1, 2, 3, 4, 5]
Example:
print(calculate_sum(list1)) should output 15.
You are not allowed to use any built... | codefeedback |
Create a function to find the maximum element of a 4x4 matrix.
myMatrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
In addition to finding the maximum element, also return its row and column index in the matrix. | codefeedback |
Create a function to convert a given number of seconds to years, months, weeks, and days. | codefeedback |
Write a JavaScript code snippet that displays the Fibonacci sequence up to the nth term on the webpage, where n is a positive integer provided by the user. | codefeedback |
Build an algorithm to find all prime numbers within a given range. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.